Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Ensure flagged users do not appear on TV #15481

Draft
wants to merge 2 commits into
base: master
Choose a base branch
from
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 5 additions & 1 deletion modules/db/src/main/Env.scala
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,8 @@ import com.softwaremill.tagging.*
import com.typesafe.config.Config
import play.api.Configuration
import reactivemongo.api.*
import lila.core.LightUser.GetterSync
import lila.core.user.UserApi

import lila.common.Lilakka

Expand All @@ -15,7 +17,9 @@ trait YoloDb
@Module
final class Env(
appConfig: Configuration,
shutdown: CoordinatedShutdown
shutdown: CoordinatedShutdown,
lightUserSync: GetterSync,
userApi: UserApi
)(using Executor):

private val driver = new AsyncDriver(appConfig.get[Config]("mongodb").some)
Expand Down
19 changes: 13 additions & 6 deletions modules/tv/src/main/TvSyncActor.scala
Original file line number Diff line number Diff line change
Expand Up @@ -5,9 +5,11 @@ import play.api.libs.json.Json

import lila.common.Bus
import lila.common.Json.given
import lila.core.user.UserApi

final private[tv] class TvSyncActor(
lightUserApi: lila.core.user.LightUserApi,
userApi: UserApi,
onTvGame: lila.game.core.OnTvGame,
gameProxy: lila.core.game.GameProxy,
rematches: lila.game.Rematches
Expand Down Expand Up @@ -51,12 +53,17 @@ final private[tv] class TvSyncActor(

case lila.core.game.StartGame(g) =>
if g.hasClock then
val candidate = Tv.Candidate(g, g.userIds.exists(lightUserApi.isBotSync))
channelActors
.collect {
case (chan, actor) if chan.filter(candidate) => actor
}
.foreach(_.addCandidate(g))
userApi
.countEngines(g.userIds)
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

this adds a hit to the database every time a game starts, so about 5 million requests a day.

Copy link
Contributor

@bastianpedersen bastianpedersen Jun 26, 2024

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Could you propose an alternative solution? I am asking out of curiosity as I am trying to get a better understanding of the codebase.

.map(nb =>
if nb == 0 then
val candidate = Tv.Candidate(g, g.userIds.exists(lightUserApi.isBotSync))
channelActors
.collect {
case (chan, actor) if chan.filter(candidate) => actor
}
.foreach(_.addCandidate(g))
)

case s @ TvSyncActor.Select => channelActors.foreach(_._2 ! s)

Expand Down
Loading