move perf_stat collection to YoloDb
parent
fb874b7858
commit
d2c81eb012
|
@ -266,9 +266,6 @@ shutup {
|
|||
playban {
|
||||
collection.playban = playban
|
||||
}
|
||||
perfStat {
|
||||
collection.perf_stat = "perf_stat"
|
||||
}
|
||||
push {
|
||||
collection {
|
||||
device = push_device
|
||||
|
|
|
@ -2,27 +2,27 @@ package lila.perfStat
|
|||
|
||||
import akka.actor._
|
||||
import com.softwaremill.macwire._
|
||||
import com.softwaremill.tagging._
|
||||
import play.api.Configuration
|
||||
|
||||
import lila.common.config._
|
||||
|
||||
@Module
|
||||
final class Env(
|
||||
appConfig: Configuration,
|
||||
lightUser: lila.common.LightUser.GetterSync,
|
||||
lightUserApi: lila.user.LightUserApi,
|
||||
gameRepo: lila.game.GameRepo,
|
||||
userRepo: lila.user.UserRepo,
|
||||
rankingsOf: lila.user.RankingsOf,
|
||||
rankingApi: lila.user.RankingApi,
|
||||
db: lila.db.Db
|
||||
yoloDb: lila.db.AsyncDb @@ lila.db.YoloDb
|
||||
)(implicit
|
||||
ec: scala.concurrent.ExecutionContext,
|
||||
system: ActorSystem
|
||||
) {
|
||||
|
||||
private lazy val storage = new PerfStatStorage(
|
||||
coll = db(appConfig.get[CollName]("perfStat.collection.perf_stat"))
|
||||
coll = yoloDb(CollName("perf_stat")).failingSilently()
|
||||
)
|
||||
|
||||
lazy val indexer = wire[PerfStatIndexer]
|
||||
|
|
|
@ -2,11 +2,12 @@ package lila.perfStat
|
|||
|
||||
import reactivemongo.api.bson._
|
||||
|
||||
import lila.db.AsyncCollFailingSilently
|
||||
import lila.db.dsl._
|
||||
import lila.rating.BSONHandlers.perfTypeIdHandler
|
||||
import lila.rating.PerfType
|
||||
|
||||
final class PerfStatStorage(coll: Coll)(implicit ec: scala.concurrent.ExecutionContext) {
|
||||
final class PerfStatStorage(coll: AsyncCollFailingSilently)(implicit ec: scala.concurrent.ExecutionContext) {
|
||||
|
||||
implicit private val UserIdBSONHandler = stringAnyValHandler[UserId](_.value, UserId.apply)
|
||||
implicit private val RatingAtBSONHandler = Macros.handler[RatingAt]
|
||||
|
@ -22,13 +23,12 @@ final class PerfStatStorage(coll: Coll)(implicit ec: scala.concurrent.ExecutionC
|
|||
implicit private val PerfStatBSONHandler = Macros.handler[PerfStat]
|
||||
|
||||
def find(userId: String, perfType: PerfType): Fu[Option[PerfStat]] =
|
||||
coll.byId[PerfStat](PerfStat.makeId(userId, perfType))
|
||||
coll(_.byId[PerfStat](PerfStat.makeId(userId, perfType)))
|
||||
|
||||
def insert(perfStat: PerfStat): Funit =
|
||||
coll.insert.one(perfStat).void
|
||||
|
||||
def update(a: PerfStat, b: PerfStat): Funit = {
|
||||
coll(_.insert.one(perfStat).void)
|
||||
|
||||
def update(a: PerfStat, b: PerfStat): Funit = coll { c =>
|
||||
val sets = $doc(
|
||||
docDiff(a.count, b.count).mapKeys(k => s"count.$k").toList :::
|
||||
List(
|
||||
|
@ -77,7 +77,7 @@ final class PerfStatStorage(coll: Coll)(implicit ec: scala.concurrent.ExecutionC
|
|||
).flatten
|
||||
)
|
||||
|
||||
coll.update
|
||||
c.update
|
||||
.one($id(a.id), $doc("$set" -> sets))
|
||||
.void
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue