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