convert isStreamer to an async cache

This commit is contained in:
Thibault Duplessis 2017-01-25 10:38:55 +01:00
parent ca9b094786
commit c4051cf3f9
4 changed files with 12 additions and 13 deletions

View file

@ -39,7 +39,7 @@ final class Env(
getRatingChart = Env.history.ratingChartApi.apply,
getRanks = Env.user.cached.ranking.getAll,
isHostingSimul = Env.simul.isHosting,
isStreamer = Env.tv.isStreamer.apply,
fetchIsStreamer = Env.tv.isStreamer.apply,
fetchIsCoach = Env.coach.api.isListedCoach,
insightShare = Env.insight.share,
getPlayTime = Env.game.playTime.apply,

View file

@ -63,11 +63,12 @@ object Plan extends LilaController {
nbFollowers <- Env.relation.api.countFollowers(me.id)
nbFollowing <- Env.relation.api.countFollowing(me.id)
nbForumPosts <- Env.forum.postApi.nbByUser(me.id)
isStreamer <- Env.tv.isStreamer(me.id)
} yield lila.plan.PlanTrackingUserData(
user = me,
nbTournaments = tournaments.allPerfResults.nb,
medianTournamentRank = tournaments.allPerfResults.rankPercentMedian,
isStreamer = Env.tv.isStreamer(me.id),
isStreamer = isStreamer,
nbFollowers = nbFollowers,
nbFollowing = nbFollowing,
nbForumPosts = nbForumPosts)

View file

@ -72,7 +72,7 @@ object UserInfo {
getRatingChart: User => Fu[Option[String]],
getRanks: String => Fu[Map[String, Int]],
isHostingSimul: String => Fu[Boolean],
isStreamer: String => Boolean,
fetchIsStreamer: String => Fu[Boolean],
fetchIsCoach: User => Fu[Boolean],
insightShare: lila.insight.Share,
getPlayTime: User => Fu[User.PlayTime],
@ -88,11 +88,12 @@ object UserInfo {
studyRepo.countByOwner(user.id) zip
trophyApi.findByUser(user) zip
fetchIsCoach(user) zip
fetchIsStreamer(user.id) zip
(user.count.rated >= 10).??(insightShare.grant(user, ctx.me)) zip
getPlayTime(user) zip
completionRate(user.id) zip
bookmarkApi.countByUser(user) flatMap {
case ((((((((((((((ranks, nbPlaying), nbImported), crosstable), ratingChart), nbFollowers), nbBlockers), nbPosts), nbStudies), trophies), isCoach), insightVisible), playTime), completionRate), nbBookmarks) =>
case (((((((((((((((ranks, nbPlaying), nbImported), crosstable), ratingChart), nbFollowers), nbBlockers), nbPosts), nbStudies), trophies), isCoach), isStreamer), insightVisible), playTime), completionRate), nbBookmarks) =>
(nbPlaying > 0) ?? isHostingSimul(user.id) map { hasSimul =>
new UserInfo(
user = user,
@ -109,7 +110,7 @@ object UserInfo {
nbStudies = nbStudies,
playTime = playTime,
trophies = trophies,
isStreamer = isStreamer(user.id),
isStreamer = isStreamer,
isCoach = isCoach,
insightVisible = insightVisible,
completionRate = completionRate)

View file

@ -5,7 +5,7 @@ import com.typesafe.config.Config
import lila.common.PimpedConfig._
import lila.db.dsl._
import lila.memo.Syncache
import lila.memo.AsyncCache
import scala.concurrent.duration._
@ -53,14 +53,11 @@ final class Env(
})
object isStreamer {
private val cache = new Syncache[Boolean, Set[String]](
private val cache = AsyncCache.single[Set[lila.user.User.ID]](
name = "tv.streamers",
compute = _ => streamerList.lichessIds,
default = _ => Set.empty,
strategy = Syncache.WaitAfterUptime(50 millis),
timeToLive = 10 seconds,
logger = logger)(system)
def apply(id: String) = cache get true contains id
f = streamerList.lichessIds,
timeToLive = 10 seconds)
def apply(id: lila.user.User.ID): Fu[Boolean] = cache(true) map { _ contains id }
}
object streamsOnAir {