Skip to content

Commit

Permalink
fix fide player sync monitoring
Browse files Browse the repository at this point in the history
there are 1,500,000 players, not 15,000

count the players, not the batches
  • Loading branch information
ornicar committed Oct 23, 2024
1 parent 3c9ddfc commit 43781aa
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 5 deletions.
7 changes: 5 additions & 2 deletions modules/common/src/main/LilaStream.scala
Original file line number Diff line number Diff line change
Expand Up @@ -23,8 +23,11 @@ object LilaStream:
flowRate[T](metric, outputDelay)
.to(Sink.foreach(r => logger.info(s"[rate] $name ${r.toInt}")))

val sinkCount = Sink.fold[Int, Any](0): (total, _) =>
val sinkCount: Sink[Any, Future[Int]] = Sink.fold[Int, Any](0): (total, _) =>
total + 1

def collect[A] = Flow[Option[A]].collect:
val sinkSum: Sink[Int, Future[Int]] = Sink.fold[Int, Int](0): (total, nb) =>
total + nb

def collect[A]: Flow[Option[A], A, NotUsed] = Flow[Option[A]].collect:
case Some(a) => a
6 changes: 3 additions & 3 deletions modules/fide/src/main/FidePlayerSync.scala
Original file line number Diff line number Diff line change
Expand Up @@ -114,7 +114,7 @@ final private class FidePlayerSync(repo: FideRepo, ws: StandaloneWSClient)(using
.mapConcat(_.toList)
.grouped(100)
.mapAsync(1)(upsert)
.runWith(lila.common.LilaStream.sinkCount)
.runWith(lila.common.LilaStream.sinkSum)
.monSuccess(_.fideSync.time)
.flatMap: nb =>
lila.mon.fideSync.players.update(nb)
Expand Down Expand Up @@ -161,7 +161,7 @@ final private class FidePlayerSync(repo: FideRepo, ws: StandaloneWSClient)(using
fetchedAt = nowInstant
)

private def upsert(ps: Seq[FidePlayer]) =
private def upsert(ps: Seq[FidePlayer]): Future[Int] =
val update = repo.playerColl.update(ordered = false)
for
elements <- ps.toList.sequentially: p =>
Expand All @@ -171,7 +171,7 @@ final private class FidePlayerSync(repo: FideRepo, ws: StandaloneWSClient)(using
upsert = true
)
_ <- elements.nonEmpty.so(update.many(elements).void)
yield ()
yield elements.size

private def setDeletedFlags(date: Instant): Fu[Int] = for
nbDeleted <- repo.playerColl.update
Expand Down

0 comments on commit 43781aa

Please sign in to comment.