Skip to content

Commit 3db0720

Browse files
committed
stop counting viewers of broadcast rounds finished 3 days ago
1 parent a767ffd commit 3db0720

File tree

2 files changed

+17
-9
lines changed

2 files changed

+17
-9
lines changed

modules/relay/src/main/RelayRound.scala

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -71,6 +71,10 @@ case class RelayRound(
7171
case Some(at) => at.isBefore(nowInstant.minusHours(3))
7272
case None => createdAt.isBefore(nowInstant.minusDays(1))
7373

74+
def daysSinceFinished =
75+
import java.time.temporal.ChronoUnit
76+
finishedAt.map(ChronoUnit.DAYS.between(_, nowInstant))
77+
7478
def withSync(f: Update[RelayRound.Sync]) = copy(sync = f(sync))
7579

7680
def withTour(tour: RelayTour) = RelayRound.WithTour(this, tour)

modules/relay/src/main/RelayStatsApi.scala

Lines changed: 13 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -14,20 +14,24 @@ final class RelayStatsApi(colls: RelayColls, viewerCount: lila.memo.ViewerCountA
1414
import RelayStats.*
1515

1616
object viewers:
17-
private def maxCountIfRecent(tour: RelayTour) =
18-
tour.tier
19-
.map:
20-
case RelayTour.Tier.normal => 1_000
21-
case RelayTour.Tier.high => 10_000
22-
case RelayTour.Tier.best => 100_000
23-
.ifTrue(tour.daysSinceFinished.forall(_ <= 1))
17+
2418
def hit(rt: RelayRound.WithTour)(using ctx: lila.ui.Context): Unit =
25-
maxCountIfRecent(rt.tour).foreach: maxCount =>
19+
maxCountIfRecent(rt).foreach: maxCount =>
2620
viewerCount.hit(rt.round.id.value, maxCount)(ctx.req, ctx.userId)
21+
2722
def get(rt: RelayRound.WithTour): Fu[Int] =
28-
maxCountIfRecent(rt.tour).nonEmpty.so:
23+
maxCountIfRecent(rt).nonEmpty.so:
2924
rt.tour.official.so(viewerCount.get(rt.round.id.value))
3025

26+
private def maxCountIfRecent(rt: RelayRound.WithTour) =
27+
rt.tour.tier
28+
.map:
29+
case RelayTour.Tier.normal => 1_000
30+
case RelayTour.Tier.high => 10_000
31+
case RelayTour.Tier.best => 100_000
32+
.ifTrue(rt.round.daysSinceFinished.forall(_ <= 3))
33+
.ifTrue(rt.tour.daysSinceFinished.forall(_ <= 1))
34+
3135
// one measurement by minute at most; the storage depends on it.
3236
scheduler.scheduleWithFixedDelay(2.minutes, 2.minutes)(() => record())
3337

0 commit comments

Comments
 (0)