Skip to content

Commit 7ee2476

Browse files
authored
Merge pull request #19619 from allanjoseph98/relayplayers-prestart-optimization
Broadcasts: skip calculating player stats until at least one game is finished
2 parents 6297703 + 6a48a61 commit 7ee2476

File tree

1 file changed

+15
-10
lines changed

1 file changed

+15
-10
lines changed

modules/relay/src/main/RelayPlayer.scala

Lines changed: 15 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -242,16 +242,21 @@ private final class RelayPlayerApi(
242242
.flatMapz: tour =>
243243
for
244244
players <- readGamesAndPlayers(sg.toList)
245-
withScore = if tour.showScores then computeScores(players) else players
246-
withRatingDiff <-
247-
if tour.showRatingDiffs then computeRatingDiffs(withScore)
248-
else fuccess(withScore)
249-
withTiebreaks <- tour.tiebreaks.fold(fuccess(withRatingDiff)): tiebreaks =>
250-
roundRepo
251-
.idsByTourOrdered(sg.last)
252-
.map(_.lastOption)
253-
.map(computeTiebreaks(withRatingDiff, tiebreaks, _))
254-
yield withTiebreaks
245+
atLeastOneGameFinished = players.exists(_._2.games.exists(_.points.isDefined))
246+
result <-
247+
if !atLeastOneGameFinished then fuccess(players)
248+
else
249+
val withScore = if tour.showScores then computeScores(players) else players
250+
for
251+
withRatingDiff <-
252+
if tour.showRatingDiffs then computeRatingDiffs(withScore) else fuccess(withScore)
253+
withTiebreaks <- tour.tiebreaks.fold(fuccess(withRatingDiff)): tiebreaks =>
254+
roundRepo
255+
.idsByTourOrdered(sg.last)
256+
.map(_.lastOption)
257+
.map(computeTiebreaks(withRatingDiff, tiebreaks, _))
258+
yield withTiebreaks
259+
yield result
255260

256261
private def sgIsParallel(tours: List[RelayTour]): Boolean =
257262
tours.headOption

0 commit comments

Comments
 (0)