From f2e0879d74c266a24a8277422836edd9147d9765 Mon Sep 17 00:00:00 2001 From: Thibault Duplessis Date: Wed, 30 Oct 2024 13:42:50 +0100 Subject: [PATCH] remove FidePlayer.{deleted,fetchedAt} the fields are no longer compatible with the new sync method --- modules/fide/src/main/FidePlayer.scala | 3 +-- modules/fide/src/main/FidePlayerSync.scala | 19 ++++--------------- modules/fide/src/main/FideRepo.scala | 2 +- 3 files changed, 6 insertions(+), 18 deletions(-) diff --git a/modules/fide/src/main/FidePlayer.scala b/modules/fide/src/main/FidePlayer.scala index d278a1ad945c..f28eb93be705 100644 --- a/modules/fide/src/main/FidePlayer.scala +++ b/modules/fide/src/main/FidePlayer.scala @@ -20,8 +20,7 @@ case class FidePlayer( blitz: Option[Elo], blitzK: Option[KFactor], year: Option[Int], - inactive: Boolean, - fetchedAt: Instant + inactive: Boolean ) extends lila.core.fide.Player: def ratingOf(tc: FideTC): Option[Elo] = tc match diff --git a/modules/fide/src/main/FidePlayerSync.scala b/modules/fide/src/main/FidePlayerSync.scala index 652009b38dc1..5fa8c6e44d08 100644 --- a/modules/fide/src/main/FidePlayerSync.scala +++ b/modules/fide/src/main/FidePlayerSync.scala @@ -119,13 +119,11 @@ final private class FidePlayerSync(repo: FideRepo, ws: StandaloneWSClient)(using .mapAsync(1)(saveIfChanged) .runWith(lila.common.LilaStream.sinkSum) .monSuccess(_.fideSync.time) - _ = lila.mon.fideSync.updated.update(nbUpdated) nbAll <- repo.player.countAll - _ = lila.mon.fideSync.players.update(nbAll) - nbDeleted <- setDeletedFlags(startAt) yield - lila.mon.fideSync.deleted.update(nbDeleted) - logger.info(s"RelayFidePlayerApi.update upserted: $nbUpdated, deleted: $nbDeleted") + lila.mon.fideSync.updated.update(nbUpdated) + lila.mon.fideSync.players.update(nbAll) + logger.info(s"RelayFidePlayerApi.update upserted: $nbUpdated, total: $nbAll") yield () /* @@ -161,8 +159,7 @@ final private class FidePlayerSync(repo: FideRepo, ws: StandaloneWSClient)(using blitz = rating(139), blitzK = kFactor(149), year = year, - inactive = flags.exists(_.contains("i")), - fetchedAt = nowInstant + inactive = flags.exists(_.contains("i")) ) private def saveIfChanged(players: Seq[FidePlayer]): Future[Int] = @@ -183,11 +180,3 @@ final private class FidePlayerSync(repo: FideRepo, ws: StandaloneWSClient)(using ) _ <- elements.nonEmpty.so(update.many(elements).void) yield elements.size - - private def setDeletedFlags(date: Instant): Fu[Int] = for - nbDeleted <- repo.playerColl.update - .one($doc("deleted".$ne(true), "fetchedAt".$lt(date)), $set("deleted" -> true), multi = true) - .map(_.n) - _ <- repo.playerColl.update - .one($doc("deleted" -> true, "fetchedAt".$gte(date)), $unset("deleted"), multi = true) - yield nbDeleted diff --git a/modules/fide/src/main/FideRepo.scala b/modules/fide/src/main/FideRepo.scala index 86a5ed2693af..b7c794d8790c 100644 --- a/modules/fide/src/main/FideRepo.scala +++ b/modules/fide/src/main/FideRepo.scala @@ -13,7 +13,7 @@ final private class FideRepo( object player: given handler: BSONDocumentHandler[FidePlayer] = Macros.handler - val selectActive: Bdoc = $doc("deleted".$ne(true), "inactive".$ne(true)) + val selectActive: Bdoc = $doc("inactive".$ne(true)) def selectFed(fed: hub.Federation.Id): Bdoc = $doc("fed" -> fed) def sortStandard: Bdoc = $sort.desc("standard") def fetch(id: FideId): Fu[Option[FidePlayer]] = playerColl.byId[FidePlayer](id)