faster fetch games analysis during assessment

This commit is contained in:
Thibault Duplessis 2018-03-10 21:27:49 -05:00
parent aa72d2ff45
commit b89f4f7750
2 changed files with 6 additions and 4 deletions

View file

@ -16,6 +16,9 @@ object AnalysisRepo {
def byId(id: ID): Fu[Option[Analysis]] = coll.byId[Analysis](id)
def byGame(game: Game): Fu[Option[Analysis]] =
game.metadata.analysed ?? byId(game.id)
def byIds(ids: Seq[ID]): Fu[Seq[Option[Analysis]]] =
coll.optionsByOrderedIds[Analysis, Analysis.ID](ids)(_.id)

View file

@ -7,8 +7,8 @@ import lila.db.dsl._
import lila.evaluation.Statistics
import lila.evaluation.{ AccountAction, Analysed, PlayerAssessment, PlayerAggregateAssessment, PlayerFlags, PlayerAssessments, Assessible }
import lila.game.{ Game, Player, GameRepo, Source, Pov }
import lila.user.{ User, UserRepo }
import lila.report.{ SuspectId, ModId }
import lila.user.{ User, UserRepo }
import reactivemongo.api.ReadPreference
import reactivemongo.bson._
@ -81,9 +81,8 @@ final class AssessApi(
def refreshAssessByUsername(username: String): Funit = withUser(username) { user =>
(GameRepo.gamesForAssessment(user.id, 100) flatMap { gs =>
(gs map { g =>
AnalysisRepo.byId(g.id) flatMap {
case Some(a) => onAnalysisReady(g, a, false)
case _ => funit
AnalysisRepo.byGame(g) flatMap {
_ ?? { onAnalysisReady(g, _, false) }
}
}).sequenceFu.void
}) >> assessUser(user.id)