Skip to content

Commit

Permalink
Merge pull request #15576 from lenguyenthanh/lila-search-team-ingestor
Browse files Browse the repository at this point in the history
Lila search team ingestor
  • Loading branch information
ornicar authored Jun 23, 2024
2 parents 8a49093 + 335ae05 commit 1799feb
Show file tree
Hide file tree
Showing 8 changed files with 6 additions and 64 deletions.
3 changes: 0 additions & 3 deletions modules/api/src/main/Cli.scala
Original file line number Diff line number Diff line change
Expand Up @@ -5,8 +5,6 @@ import lila.web.AnnounceApi

final private[api] class Cli(
security: lila.security.Env,
teamSearch: lila.teamSearch.Env,
forumSearch: lila.forumSearch.Env,
tournament: lila.tournament.Env,
fishnet: lila.fishnet.Env,
study: lila.study.Env,
Expand Down Expand Up @@ -55,7 +53,6 @@ final private[api] class Cli(

private def processors =
security.cli.process
.orElse(teamSearch.cli.process)
.orElse(tournament.cli.process)
.orElse(fishnet.cli.process)
.orElse(study.cli.process)
Expand Down
2 changes: 0 additions & 2 deletions modules/core/src/main/team.scala
Original file line number Diff line number Diff line change
Expand Up @@ -56,8 +56,6 @@ case class TeamData(
)
case class TeamCreate(team: TeamData)
case class TeamUpdate(team: TeamData, byMod: Boolean)(using val me: MyId)
case class TeamDelete(id: TeamId)
case class TeamDisable(id: TeamId)
case class JoinTeam(id: TeamId, userId: UserId)
case class IsLeader(id: TeamId, userId: UserId, promise: Promise[Boolean])
case class IsLeaderOf(leaderId: UserId, memberId: UserId, promise: Promise[Boolean])
Expand Down
6 changes: 1 addition & 5 deletions modules/forumSearch/src/main/Env.scala
Original file line number Diff line number Diff line change
Expand Up @@ -13,11 +13,7 @@ import lila.search.spec.Query
@Module
private class ForumSearchConfig(@ConfigName("paginator.max_per_page") val maxPerPage: MaxPerPage)

final class Env(
appConfig: Configuration,
postApi: lila.core.forum.ForumPostApi,
client: SearchClient
)(using Executor):
final class Env(appConfig: Configuration, client: SearchClient)(using Executor):

private val config = appConfig.get[ForumSearchConfig]("forumSearch")(AutoConfig.loader)

Expand Down
1 change: 0 additions & 1 deletion modules/forumSearch/src/main/package.scala
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
package lila.forumSearch

export lila.core.lilaism.Lilaism.{ *, given }
export lila.common.extensions.*

private val logger = lila.log("forumSearch")

Expand Down
3 changes: 1 addition & 2 deletions modules/team/src/main/TeamApi.scala
Original file line number Diff line number Diff line change
Expand Up @@ -326,7 +326,7 @@ final class TeamApi(
users <- memberRepo.userIdsByTeam(team.id)
_ = users.foreach(cached.invalidateTeamIds)
_ <- requestRepo.removeByTeam(team.id)
yield publish(TeamDisable(team.id))
yield ()
else
teamRepo
.enable(team)
Expand All @@ -353,7 +353,6 @@ final class TeamApi(
(teamRepo.coll.delete.one($id(team.id)) >>
memberRepo.removeByTeam(team.id)).andDo {
logger.info(s"delete team ${team.id} by @${by.id}: $explain")
publish(TeamDelete(team.id))
}

def syncBelongsTo(teamId: TeamId, userId: UserId): Boolean =
Expand Down
17 changes: 1 addition & 16 deletions modules/teamSearch/src/main/Env.scala
Original file line number Diff line number Diff line change
@@ -1,17 +1,13 @@
package lila.teamSearch

import akka.actor.*
import com.softwaremill.macwire.*

import scalalib.paginator.Paginator
import lila.core.config.ConfigName
import lila.search.client.SearchClient
import lila.search.spec.Query

final class Env(
client: SearchClient,
teamApi: lila.core.team.TeamApi
)(using Executor, akka.stream.Materializer):
final class Env(client: SearchClient)(using Executor):

private val maxPerPage = MaxPerPage(15)

Expand All @@ -20,14 +16,3 @@ final class Env(
lazy val api: TeamSearchApi = wire[TeamSearchApi]

def apply(text: String, page: Int): Fu[Paginator[TeamId]] = paginatorBuilder(Query.team(text), page)

def cli: lila.common.Cli = new:
def process = { case "team" :: "search" :: "reset" :: Nil =>
api.reset.inject("done")
}

lila.common.Bus.subscribeFun("team"):
case lila.core.team.TeamCreate(team) => api.store(team)
case lila.core.team.TeamUpdate(team, _) => api.store(team)
case lila.core.team.TeamDelete(id) => client.deleteById(index, id.value)
case lila.core.team.TeamDisable(id) => client.deleteById(index, id.value)
37 changes: 3 additions & 34 deletions modules/teamSearch/src/main/TeamSearchApi.scala
Original file line number Diff line number Diff line change
@@ -1,45 +1,14 @@
package lila.teamSearch

import akka.stream.scaladsl.*

import lila.core.team.TeamData
import lila.search.*
import lila.search.client.SearchClient
import lila.search.spec.{ Query, TeamSource }
import lila.search.spec.Query

final class TeamSearchApi(
client: SearchClient,
teamApi: lila.core.team.TeamApi
)(using Executor, akka.stream.Materializer)
extends SearchReadApi[TeamId, Query.Team]:
final class TeamSearchApi(client: SearchClient)(using Executor) extends SearchReadApi[TeamId, Query.Team]:

def search(query: Query.Team, from: From, size: Size) =
client
.search(query, from, size)
.map: res =>
res.hitIds.map(TeamId.apply)
.map(_.hitIds.map(TeamId.apply))

def count(query: Query.Team) = client.count(query).dmap(_.count)

def store(team: TeamData) = client.storeTeam(team.id.value, toDoc(team))

private def toDoc(team: TeamData) =
TeamSource(
name = team.name,
description = team.description.value.take(10000),
nbMembers = team.nbMembers
)

def reset =
client.mapping(index) >> {

logger.info(s"Index to ${index}")

teamApi.cursor
.documentSource()
.via(lila.common.LilaStream.logRate[TeamData]("team index")(logger))
.map(t => t.id.value -> toDoc(t))
.grouped(200)
.mapAsync(1)(xs => client.storeBulkTeam(xs.toList))
.runWith(Sink.ignore)
} >> client.refresh(index)
1 change: 0 additions & 1 deletion modules/teamSearch/src/main/package.scala
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
package lila.teamSearch

export lila.core.lilaism.Lilaism.{ *, given }
export lila.common.extensions.*

private val logger = lila.log("teamSearch")

Expand Down

0 comments on commit 1799feb

Please sign in to comment.