build mod leaderboard from a DB secondary

pull/3876/head
Thibault Duplessis 2017-12-05 18:35:56 -05:00
parent 246aa1d3ae
commit c924db8c80
1 changed files with 4 additions and 2 deletions

View File

@ -3,6 +3,7 @@ package lila.mod
import lila.db.BSON.BSONJodaDateTimeHandler
import org.joda.time.DateTime
import reactivemongo.api.collections.bson.BSONBatchCommands.AggregationFramework._
import reactivemongo.api.ReadPreference
import reactivemongo.bson._
import scala.concurrent.duration._
@ -98,14 +99,15 @@ final class Gamify(
}
private def reportLeaderboard(after: DateTime, before: Option[DateTime]): Fu[List[ModCount]] =
reportApi.coll.aggregate(
reportApi.coll.aggregateWithReadPreference(
Match($doc(
"atoms.0.at" -> dateRange(after, before),
"processedBy" -> notLichess
)), List(
GroupField("processedBy")("nb" -> SumValue(1)),
Sort(Descending("nb"))
)
),
readPreference = ReadPreference.secondaryPreferred
).map {
_.firstBatch.flatMap { obj =>
obj.getAs[String]("_id") |@| obj.getAs[Int]("nb") apply ModCount.apply