From d32f7f4d8fbfa7a969cd571d7ed6ba95663698f2 Mon Sep 17 00:00:00 2001 From: Thibault Duplessis Date: Sun, 23 Apr 2023 10:37:58 +0200 Subject: [PATCH 1/4] fix relay sync.period --- app/views/relay/roundForm.scala | 8 +++++--- modules/relay/src/main/RelayFetch.scala | 4 ++-- 2 files changed, 7 insertions(+), 5 deletions(-) diff --git a/app/views/relay/roundForm.scala b/app/views/relay/roundForm.scala index 2a210ee6c0d24..12dc0d5860cc4 100644 --- a/app/views/relay/roundForm.scala +++ b/app/views/relay/roundForm.scala @@ -100,9 +100,11 @@ object roundForm: )(form3.flatpickr(_, minDate = None)), isGranted(_.Relay) option form3.group( - form("throttle"), - raw("Throttle in seconds"), - help = raw("Optional, to manually throttle requests. Min 2s, max 60s.").some, + form("period"), + raw("Period in seconds"), + help = raw( + "Optional, how long to wait between requests. Min 2s, max 60s. Defaults to automatic based on the number of viewers." + ).some, half = true )(form3.input(_, typ = "number")) ), diff --git a/modules/relay/src/main/RelayFetch.scala b/modules/relay/src/main/RelayFetch.scala index 522db13b69695..e1f2eec33e0ba 100644 --- a/modules/relay/src/main/RelayFetch.scala +++ b/modules/relay/src/main/RelayFetch.scala @@ -111,7 +111,7 @@ final private class RelayFetch( .filterNot(_ contains "Found an empty PGN") .foreach { irc.broadcastError(rt.round.id.value, rt.fullName, _) } Seconds(60) - else rt.round.sync.delay | Seconds(if upstream.local then 3 else 6) + else rt.round.sync.period | Seconds(if upstream.local then 3 else 6) rt.round.withSync { _.copy( nextAt = nowInstant plusSeconds { @@ -144,7 +144,7 @@ final private class RelayFetch( gameProxy.upgradeIfPresent flatMap gameRepo.withInitialFens flatMap { games => if (games.size == ids.size) - games.map { case (game, fen) => + games.map { (game, fen) => pgnDump(game, fen, gameIdsUpstreamPgnFlags).dmap(_.render) }.parallel dmap MultiPgn.apply else From 7dc1df1eba9684f1cf7b947e680db02b232624df Mon Sep 17 00:00:00 2001 From: Niklas Fiekas Date: Sun, 23 Apr 2023 11:31:22 +0200 Subject: [PATCH 2/4] remove unused showPeriod (#12670) --- app/templating/DateHelper.scala | 2 +- modules/i18n/src/main/PeriodLocales.scala | 5 +---- 2 files changed, 2 insertions(+), 5 deletions(-) diff --git a/app/templating/DateHelper.scala b/app/templating/DateHelper.scala index 046e43a054fa8..60f2fa70ae6fd 100644 --- a/app/templating/DateHelper.scala +++ b/app/templating/DateHelper.scala @@ -12,7 +12,7 @@ import chess.format.pgn.Tag.Date trait DateHelper { self: I18nHelper with StringHelper with NumberHelper => - export PeriodLocales.{ showPeriod, showDuration } + export PeriodLocales.showDuration private val dateTimeStyle = "MS" private val dateStyle = "M-" diff --git a/modules/i18n/src/main/PeriodLocales.scala b/modules/i18n/src/main/PeriodLocales.scala index 4043db7a06bfa..34961f2e1bcff 100644 --- a/modules/i18n/src/main/PeriodLocales.scala +++ b/modules/i18n/src/main/PeriodLocales.scala @@ -3,7 +3,7 @@ package lila.i18n import org.joda.time.format.{ PeriodFormat, PeriodFormatter } import org.joda.time.{ DurationFieldType, PeriodType, Period as JodaPeriod } import play.api.i18n.Lang -import java.time.{ Duration, Period } +import java.time.Duration // TODO replace with threeten-extra? // https://www.threeten.org/threeten-extra/apidocs/org.threeten.extra/org/threeten/extra/AmountFormats.html @@ -18,8 +18,5 @@ object PeriodLocales: private def periodFormatter(using lang: Lang): PeriodFormatter = PeriodFormat wordBased lang.locale - def showPeriod(period: Period)(using Lang): String = - periodFormatter print JodaPeriod(period).normalizedStandard(periodType) - def showDuration(duration: Duration)(using Lang): String = periodFormatter print JodaPeriod(duration.toMillis).normalizedStandard(periodType) From 03bac54a68c09e36b5799684da82c4d0fb4861e5 Mon Sep 17 00:00:00 2001 From: Thibault Duplessis Date: Sun, 23 Apr 2023 14:31:31 +0200 Subject: [PATCH 3/4] fix manually setting date of swiss first round --- modules/swiss/src/main/SwissApi.scala | 15 ++++++--------- 1 file changed, 6 insertions(+), 9 deletions(-) diff --git a/modules/swiss/src/main/SwissApi.scala b/modules/swiss/src/main/SwissApi.scala index d43e2e7268b63..a64ed7dc1e56e 100644 --- a/modules/swiss/src/main/SwissApi.scala +++ b/modules/swiss/src/main/SwissApi.scala @@ -4,6 +4,7 @@ import akka.stream.scaladsl.* import alleycats.Zero import java.nio.charset.StandardCharsets.UTF_8 import java.security.MessageDigest +import java.time.format.{ DateTimeFormatter, FormatStyle } import reactivemongo.akkastream.cursorProducer import reactivemongo.api.* import reactivemongo.api.bson.* @@ -145,24 +146,20 @@ final class SwissApi( def scheduleNextRound(swiss: Swiss, date: Instant): Funit = Sequencing(swiss.id)(cache.swissCache.notFinishedById) { old => - (!old.settings.manualRounds).?? { - mongo.swiss + for + _ <- !old.settings.manualRounds ?? mongo.swiss .updateField($id(old.id), "settings.i", Swiss.RoundInterval.manual) .void - } >> { - if (old.isCreated) mongo.swiss.updateField($id(old.id), "startsAt", date).void - else if (old.isStarted && old.nbOngoing == 0) + _ <- old.isCreated ?? mongo.swiss.updateField($id(old.id), "startsAt", date).void + _ <- (!old.isFinished && old.nbOngoing == 0) ?? mongo.swiss.updateField($id(old.id), "nextRoundAt", date).void >>- { - import java.time.format.{ DateTimeFormatter, FormatStyle } val formatter = DateTimeFormatter.ofLocalizedDateTime(FormatStyle.MEDIUM, FormatStyle.SHORT) val showDate = formatter print date systemChat(swiss.id, s"Round ${swiss.round.value + 1} scheduled at $showDate UTC") } - else funit - } >>- { + yield cache.swissCache clear swiss.id socket.reload(swiss.id) - } } def verdicts(swiss: Swiss, me: Option[User]): Fu[SwissCondition.All.WithVerdicts] = From 75b747a94cce9c9deba8cd45c0ba5335769cd99e Mon Sep 17 00:00:00 2001 From: Thibault Duplessis Date: Mon, 24 Apr 2023 10:51:58 +0200 Subject: [PATCH 4/4] upgrade reactivemongo --- project/Dependencies.scala | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/project/Dependencies.scala b/project/Dependencies.scala index 21ab001735199..0ad4d2708a1f6 100644 --- a/project/Dependencies.scala +++ b/project/Dependencies.scala @@ -57,7 +57,7 @@ object Dependencies { } object reactivemongo { - val driver = "org.reactivemongo" %% "reactivemongo" % "1.1.0-RC7" + val driver = "org.reactivemongo" %% "reactivemongo" % "1.1.0-RC9" val stream = "org.reactivemongo" %% "reactivemongo-akkastream" % "1.1.0-RC9" val shaded = "org.reactivemongo" % "reactivemongo-shaded-native" % s"1.1.0-RC6-$os-x86-64" // val kamon = "org.reactivemongo" %% "reactivemongo-kamon" % "1.0.8"