never wait for ranking computation
parent
1fd57bc4da
commit
fbd5d06da5
|
@ -148,14 +148,13 @@ object UserInfo {
|
|||
streamerApi.isActualStreamer(user).mon(_.user segment "streamer") zip
|
||||
(user.count.rated >= 10).??(insightShare.grant(user, ctx.me)) zip
|
||||
playbanApi.completionRate(user.id).mon(_.user segment "completion") zip
|
||||
(nbs.playing > 0) ?? isHostingSimul(user.id).mon(_.user segment "simul") zip
|
||||
userCached.rankingsOf(user.id) map {
|
||||
(nbs.playing > 0) ?? isHostingSimul(user.id).mon(_.user segment "simul") map {
|
||||
// format: off
|
||||
case ((((((((((((((ratingChart, nbFollowers), nbForumPosts), ublog), nbStudies), trophies), shields), revols), teamIds), isCoach), isStreamer), insightVisible), completionRate), hasSimul), ranks) =>
|
||||
case (((((((((((((ratingChart, nbFollowers), nbForumPosts), ublog), nbStudies), trophies), shields), revols), teamIds), isCoach), isStreamer), insightVisible), completionRate), hasSimul) =>
|
||||
// format: on
|
||||
new UserInfo(
|
||||
user = user,
|
||||
ranks = ranks,
|
||||
ranks = userCached.rankingsOf(user.id),
|
||||
nbs = nbs,
|
||||
hasSimul = hasSimul,
|
||||
ratingChart = ratingChart,
|
||||
|
|
|
@ -34,7 +34,6 @@ final class PerfStatApi(
|
|||
(u.enabled && (!u.lame || by.exists(u.is))) || by.??(Granter(_.UserModView))
|
||||
} ?? { u =>
|
||||
for {
|
||||
ranks <- rankingsOf(u.id)
|
||||
oldPerfStat <- get(u, perfType)
|
||||
perfStat = oldPerfStat.copy(playStreak = oldPerfStat.playStreak.checkCurrent)
|
||||
distribution <- u.perfs(perfType).established ?? {
|
||||
|
@ -47,7 +46,7 @@ final class PerfStatApi(
|
|||
}
|
||||
_ = lightUserApi preloadUser u
|
||||
_ <- lightUserApi preloadMany perfStat.userIds.map(_.value)
|
||||
} yield PerfStatData(u, perfStat, ranks, percentile).some
|
||||
} yield PerfStatData(u, perfStat, rankingsOf(u.id), percentile).some
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
@ -88,7 +88,7 @@ final class Cached(
|
|||
|
||||
def getTop50Online = top50OnlineCache.getUnit
|
||||
|
||||
def rankingsOf(userId: User.ID): Fu[lila.rating.UserRankMap] = rankingApi.weeklyStableRanking of userId
|
||||
def rankingsOf(userId: User.ID): lila.rating.UserRankMap = rankingApi.weeklyStableRanking of userId
|
||||
|
||||
private[user] val botIds = cacheApi.unit[Set[User.ID]] {
|
||||
_.refreshAfterWrite(10 minutes)
|
||||
|
|
|
@ -3,11 +3,12 @@ package lila.user
|
|||
import org.joda.time.DateTime
|
||||
import reactivemongo.api.bson._
|
||||
import scala.concurrent.duration._
|
||||
import scala.util.Success
|
||||
|
||||
import lila.db.AsyncCollFailingSilently
|
||||
import lila.db.dsl._
|
||||
import lila.memo.CacheApi._
|
||||
import lila.rating.{ Glicko, Perf, PerfType }
|
||||
import lila.db.AsyncCollFailingSilently
|
||||
|
||||
final class RankingApi(
|
||||
userRepo: UserRepo,
|
||||
|
@ -15,7 +16,7 @@ final class RankingApi(
|
|||
cacheApi: lila.memo.CacheApi,
|
||||
mongoCache: lila.memo.MongoCache.Api,
|
||||
lightUser: lila.common.LightUser.Getter
|
||||
)(implicit ec: scala.concurrent.ExecutionContext) {
|
||||
)(implicit ec: scala.concurrent.ExecutionContext, system: akka.actor.ActorSystem) {
|
||||
|
||||
import RankingApi._
|
||||
implicit private val rankingBSONHandler = Macros.handler[Ranking]
|
||||
|
@ -110,11 +111,13 @@ final class RankingApi(
|
|||
|
||||
private type Rank = Int
|
||||
|
||||
def of(userId: User.ID): Fu[Map[PerfType, Rank]] =
|
||||
cache.getUnit map { all =>
|
||||
all.flatMap { case (pt, ranking) =>
|
||||
ranking get userId map (pt -> _)
|
||||
}
|
||||
def of(userId: User.ID): Map[PerfType, Rank] =
|
||||
cache.getUnit.value match {
|
||||
case Some(Success(all)) =>
|
||||
all.flatMap { case (pt, ranking) =>
|
||||
ranking get userId map (pt -> _)
|
||||
}
|
||||
case _ => Map.empty
|
||||
}
|
||||
|
||||
private val cache = cacheApi.unit[Map[PerfType, Map[User.ID, Rank]]] {
|
||||
|
@ -124,7 +127,7 @@ final class RankingApi(
|
|||
.linear(PerfType.leaderboardable) { pt =>
|
||||
compute(pt).dmap(pt -> _)
|
||||
}
|
||||
.dmap(_.toMap)
|
||||
.map(_.toMap)
|
||||
.chronometer
|
||||
.logIfSlow(500, logger.branch("ranking"))(_ => "slow weeklyStableRanking")
|
||||
.result
|
||||
|
|
|
@ -4,8 +4,7 @@ final class GetBotIds(f: () => Fu[Set[User.ID]]) extends (() => Fu[Set[User.ID]]
|
|||
def apply() = f()
|
||||
}
|
||||
|
||||
final class RankingsOf(f: User.ID => Fu[lila.rating.UserRankMap])
|
||||
extends (User.ID => Fu[lila.rating.UserRankMap]) {
|
||||
final class RankingsOf(f: User.ID => lila.rating.UserRankMap) extends (User.ID => lila.rating.UserRankMap) {
|
||||
def apply(u: User.ID) = f(u)
|
||||
}
|
||||
|
||||
|
|
Loading…
Reference in New Issue