Skip to content

Commit

Permalink
remove FidePlayer.{deleted,fetchedAt}
Browse files Browse the repository at this point in the history
the fields are no longer compatible with the new sync method
  • Loading branch information
ornicar committed Oct 30, 2024
1 parent 4da4ae2 commit f2e0879
Show file tree
Hide file tree
Showing 3 changed files with 6 additions and 18 deletions.
3 changes: 1 addition & 2 deletions modules/fide/src/main/FidePlayer.scala
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
19 changes: 4 additions & 15 deletions modules/fide/src/main/FidePlayerSync.scala
Original file line number Diff line number Diff line change
Expand Up @@ -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 ()

/*
Expand Down Expand Up @@ -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] =
Expand All @@ -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
2 changes: 1 addition & 1 deletion modules/fide/src/main/FideRepo.scala
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down

0 comments on commit f2e0879

Please sign in to comment.