remove donor cache and config

This commit is contained in:
Thibault Duplessis 2016-07-14 18:53:59 +02:00
parent 7a06379438
commit ab2c05870c
5 changed files with 4 additions and 26 deletions

View file

@ -38,15 +38,14 @@ object User extends LilaController {
def showMini(username: String) = Open { implicit ctx =>
OptionFuResult(UserRepo named username) { user =>
GameRepo lastPlayedPlaying user zip
Env.donation.isDonor(user.id) zip
(ctx.userId ?? { relationApi.fetchBlocks(user.id, _) }) zip
(ctx.userId ?? { Env.game.crosstableApi(user.id, _) }) zip
(ctx.isAuth ?? { Env.pref.api.followable(user.id) }) zip
(ctx.userId ?? { relationApi.fetchRelation(_, user.id) }) flatMap {
case (((((pov, donor), blocked), crosstable), followable), relation) =>
case ((((pov, blocked), crosstable), followable), relation) =>
negotiate(
html = fuccess {
Ok(html.user.mini(user, pov, blocked, followable, relation, crosstable, donor))
Ok(html.user.mini(user, pov, blocked, followable, relation, crosstable))
.withHeaders(CACHE_CONTROL -> "max-age=5")
},
api = _ => {

View file

@ -1,4 +1,4 @@
@(u: User, playing: Option[Pov], blocked: Boolean, followable: Boolean, rel: Option[lila.relation.Relation], crosstable: Option[lila.game.Crosstable], isDonor: Boolean)(implicit ctx: Context)
@(u: User, playing: Option[Pov], blocked: Boolean, followable: Boolean, rel: Option[lila.relation.Relation], crosstable: Option[lila.game.Crosstable])(implicit ctx: Context)
<div class="title">
<div>
@u.profileOrDefault.countryInfo.map {

View file

@ -103,8 +103,6 @@ qa {
donation {
collection.donation = donation
weekly_goal = 30400
server_donors = [ drazak, jaldus, intenex, thibault ]
other_donors = [ bitchess, st0rmy, arka50, feeglood, eugene_kurmanin, mastertan, lance5500, crosky, medvezhonok ]
}
chat {
collection {

View file

@ -12,20 +12,12 @@ import lila.db.dsl._
final class DonationApi(
coll: Coll,
weeklyGoal: Int,
serverDonors: Set[String],
otherDonors: Set[String],
bus: lila.common.Bus) {
private val allOtherDonors = serverDonors ++ otherDonors
private implicit val donationBSONHandler = Macros.handler[Donation]
private val minAmount = 200
private val donorCache = lila.memo.AsyncCache[String, Boolean](
userId => donatedByUser(userId).map(_ >= minAmount),
maxCapacity = 5000)
// in $ cents
private def donatedByUser(userId: String): Fu[Int] =
coll.aggregate(
@ -50,15 +42,10 @@ final class DonationApi(
_.documents.flatMap { _.getAs[String]("_id") }
}
def isDonor(userId: String) =
if (allOtherDonors contains userId) fuccess(true)
else donorCache(userId)
def create(donation: Donation) = {
coll insert donation recover
lila.db.recoverDuplicateKey(e => println(e.getMessage)) void
} >> progressCache.clear >>
donation.userId.??(donorCache.remove) >>-
} >> progressCache.clear >>-
progress.foreach { prog =>
bus.publish(lila.hub.actorApi.DonationEvent(
userId = donation.userId,

View file

@ -11,19 +11,13 @@ final class Env(
private val CollectionDonation = config getString "collection.donation"
private val WeeklyGoal = config getInt "weekly_goal"
private val ServerDonors = (config getStringList "server_donors").toSet
private val OtherDonors = (config getStringList "other_donors").toSet
def forms = DataForm
lazy val api = new DonationApi(
db(CollectionDonation),
WeeklyGoal,
serverDonors = ServerDonors,
otherDonors = OtherDonors,
bus = bus)
val isDonor = api isDonor _
}
object Env {