cache confrontation count
This commit is contained in:
parent
d3c6621eaa
commit
e1f32fa38b
|
@ -6,6 +6,7 @@ import play.api.libs.json.JsObject
|
|||
|
||||
import lila.db.api.$count
|
||||
import lila.memo.AsyncCache
|
||||
import lila.user.{ User, Confrontation }
|
||||
import tube.gameTube
|
||||
|
||||
private[game] final class Cached(ttl: Duration) {
|
||||
|
@ -15,5 +16,11 @@ private[game] final class Cached(ttl: Duration) {
|
|||
def nbPopular: Fu[Int] = count(Query.popular)
|
||||
def nbImported: Fu[Int] = count(Query.imported)
|
||||
|
||||
def confrontation(user1: User, user2: User): Fu[Confrontation] =
|
||||
confrontationCache(List(user1, user2).sortBy(_.count.game).map(_.id))
|
||||
|
||||
private val confrontationCache =
|
||||
AsyncCache(GameRepo.confrontation, timeToLive = 1.minute)
|
||||
|
||||
private val count = AsyncCache((o: JsObject) ⇒ $count(o), timeToLive = ttl)
|
||||
}
|
||||
|
|
|
@ -227,10 +227,11 @@ object GameRepo {
|
|||
)
|
||||
|
||||
// user1 wins, draws, losses
|
||||
def confrontation(user1: User, user2: User): Fu[Confrontation] = {
|
||||
// the 2 userIds SHOULD be sorted by game count desc
|
||||
// this method is cached in lila.game.Cached
|
||||
private[game] def confrontation(userIds: List[String]): Fu[Confrontation] = {
|
||||
import reactivemongo.bson._
|
||||
import reactivemongo.core.commands._
|
||||
val userIds = List(user1, user2).sortBy(_.count.game).map(_.id)
|
||||
val command = Aggregate(gameTube.coll.name, Seq(
|
||||
Match(BSONDocument(
|
||||
"uids" -> BSONDocument("$all" -> userIds),
|
||||
|
@ -247,10 +248,9 @@ object GameRepo {
|
|||
}
|
||||
}).flatten.toMap
|
||||
Confrontation(
|
||||
user1, user2,
|
||||
~(res get user1.id),
|
||||
~(res get ~userIds.lift(0)),
|
||||
~(res get ""),
|
||||
~(res get user2.id)
|
||||
~(res get ~userIds.lift(1))
|
||||
)
|
||||
}
|
||||
}
|
||||
|
|
|
@ -1,11 +1,6 @@
|
|||
package lila.user
|
||||
|
||||
case class Confrontation(
|
||||
user1: User,
|
||||
user2: User,
|
||||
wins: Int,
|
||||
draws: Int,
|
||||
losses: Int) {
|
||||
case class Confrontation(wins: Int, draws: Int, losses: Int) {
|
||||
|
||||
def games = wins + draws + losses
|
||||
|
||||
|
|
2
todo
2
todo
|
@ -61,5 +61,5 @@ real board editor save
|
|||
clickable mistakes list in analysis
|
||||
FEN/editor castle/enpassant https://github.com/ornicar/lila/issues/42 white/black to play
|
||||
user notes, shared among friends
|
||||
autopairing http://en.lichess.org/forum/general-chess-discussion/pairing#1
|
||||
detect cheat using lichess AI
|
||||
fix AI protocol
|
||||
|
|
Loading…
Reference in a new issue