preload logged in user
This commit is contained in:
parent
96de98acc3
commit
4b8c3064e0
|
@ -287,10 +287,13 @@ private[controllers] trait LilaController
|
|||
ctx.me.fold(fuccess(PageData.anon(getAssetVersion, blindMode(ctx)))) { me =>
|
||||
val isPage = HTTPRequest.isSynchronousHttp(ctx.req)
|
||||
(Env.pref.api getPref me) zip {
|
||||
if (isPage) getOnlineFriends(me) zip
|
||||
Env.team.api.nbRequests(me.id) zip
|
||||
Env.challenge.api.countInFor(me.id) zip
|
||||
Env.notifyModule.api.unreadCount(Notifies(me.id)).map(_.value)
|
||||
if (isPage) {
|
||||
Env.user.lightUserApi preloadUser me
|
||||
getOnlineFriends(me) zip
|
||||
Env.team.api.nbRequests(me.id) zip
|
||||
Env.challenge.api.countInFor(me.id) zip
|
||||
Env.notifyModule.api.unreadCount(Notifies(me.id)).map(_.value)
|
||||
}
|
||||
else fuccess {
|
||||
(((OnlineFriends.empty, 0), 0), 0)
|
||||
}
|
||||
|
|
|
@ -28,6 +28,7 @@ final class Syncache[K, V](
|
|||
|
||||
// get the value synchronously, might block depending on strategy
|
||||
def sync(k: K): V = Option(cache getIfPresent k) getOrElse {
|
||||
println(s"*** miss $name $k")
|
||||
incMiss()
|
||||
chm.computeIfAbsent(k, loadFunction)
|
||||
strategy match {
|
||||
|
@ -51,6 +52,7 @@ final class Syncache[K, V](
|
|||
|
||||
def preloadOne(k: K): Funit =
|
||||
if (cache.getIfPresent(k) == null) {
|
||||
println(s"*** preload $name $k")
|
||||
incPreload()
|
||||
chm.computeIfAbsent(k, loadFunction)
|
||||
chm.get(k).void
|
||||
|
@ -59,6 +61,12 @@ final class Syncache[K, V](
|
|||
|
||||
def preloadMany(ks: Seq[K]): Funit = ks.distinct.map(preloadOne).sequenceFu.void
|
||||
|
||||
def setOneIfAbsent(k: K, v: => V): Unit =
|
||||
if (cache.getIfPresent(k) == null) {
|
||||
incPreload()
|
||||
cache.put(k, v)
|
||||
}
|
||||
|
||||
private val loadFunction = new java.util.function.Function[K, Fu[V]] {
|
||||
def apply(k: K) = {
|
||||
compute(k).withTimeout(
|
||||
|
|
|
@ -19,6 +19,7 @@ final class LightUserApi(coll: Coll)(implicit system: akka.actor.ActorSystem) {
|
|||
|
||||
def preloadOne = cache preloadOne _
|
||||
def preloadMany = cache preloadMany _
|
||||
def preloadUser(user: User) = cache.setOneIfAbsent(user.id, user.light.some)
|
||||
|
||||
def getList(ids: List[String]): List[LightUser] = ids flatMap sync
|
||||
|
||||
|
|
Loading…
Reference in a new issue