Skip to content

Commit

Permalink
during broadcast push, lookup all db games before saying the round is…
Browse files Browse the repository at this point in the history
… complete

closes #14462
  • Loading branch information
ornicar committed Jun 26, 2024
1 parent 2ae4c6e commit 2b56c14
Showing 1 changed file with 5 additions and 2 deletions.
7 changes: 5 additions & 2 deletions modules/relay/src/main/RelayPush.scala
Original file line number Diff line number Diff line change
Expand Up @@ -7,12 +7,13 @@ import chess.{ ErrorStr, Game, Replay, Square }
import scala.concurrent.duration.*
import scalalib.actor.AsyncActorSequencers

import lila.study.{ MultiPgn, StudyPgnImport }
import lila.study.{ MultiPgn, StudyPgnImport, ChapterPreviewApi }

final class RelayPush(
sync: RelaySync,
api: RelayApi,
stats: RelayStatsApi,
chapterPreview: ChapterPreviewApi,
irc: lila.core.irc.IrcApi
)(using ActorSystem, Executor, Scheduler):

Expand Down Expand Up @@ -55,10 +56,12 @@ final class RelayPush(
_ = if !rt.round.hasStarted && !rt.tour.official && event.hasMoves then
irc.broadcastStart(rt.round.id, rt.fullName)
_ = stats.setActive(rt.round.id)
allGamesFinished <- (games.nonEmpty && games.forall(_.outcome.isDefined)).so:
chapterPreview.dataList(rt.round.studyId).map(_.forall(_.finished))
round <- api.update(rt.round): r1 =>
val r2 = r1.withSync(_.addLog(event))
val r3 = if event.hasMoves then r2.ensureStarted.resume(rt.tour.official) else r2
r3.copy(finished = games.nonEmpty && games.forall(_.outcome.isDefined))
r3.copy(finished = allGamesFinished)
_ <- andSyncTargets.so(api.syncTargetsOfSource(round))
yield ()

Expand Down

0 comments on commit 2b56c14

Please sign in to comment.