-
-
Notifications
You must be signed in to change notification settings - Fork 24
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Loading status checks…
Merge pull request #375 from lichess-org/ingestor-refactor/0
Refactor ingestor module
Showing
15 changed files
with
344 additions
and
400 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,45 @@ | ||
package lila.search | ||
package ingestor | ||
|
||
import cats.effect.IO | ||
|
||
import java.time.Instant | ||
|
||
trait Repo[A]: | ||
def watch(since: Option[Instant]): fs2.Stream[IO, Repo.Result[A]] | ||
def fetch(since: Instant, until: Instant): fs2.Stream[IO, Repo.Result[A]] | ||
|
||
object Repo: | ||
type SourceWithId[A] = (String, A) | ||
case class Result[A](toIndex: List[SourceWithId[A]], toDelete: List[Id], timestamp: Option[Instant]) | ||
|
||
import cats.effect.IO | ||
import mongo4cats.bson.Document | ||
import mongo4cats.collection.GenericMongoCollection | ||
import mongo4cats.models.collection.ChangeStreamDocument | ||
import mongo4cats.operations.Filter | ||
import org.bson.BsonTimestamp | ||
|
||
import java.time.Instant | ||
|
||
val _id = "_id" | ||
|
||
type MongoCollection = GenericMongoCollection[IO, Document, [A] =>> fs2.Stream[IO, A]] | ||
|
||
given [A]: HasDocId[ChangeStreamDocument[A]] with | ||
extension (change: ChangeStreamDocument[A]) | ||
def docId: Option[String] = | ||
change.documentKey.flatMap(_.id) | ||
|
||
extension (doc: Document) | ||
def id: Option[String] = | ||
doc.getString(_id) | ||
|
||
extension (instant: Instant) | ||
inline def asBsonTimestamp: BsonTimestamp = BsonTimestamp(instant.getEpochSecond.toInt, 1) | ||
|
||
def range(field: String)(since: Instant, until: Option[Instant]): Filter = | ||
inline def gtes = Filter.gte(field, since) | ||
until.fold(gtes)(until => gtes.and(Filter.lt(field, until))) | ||
|
||
extension (s: String) def dollarPrefix = "$" + s |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,39 @@ | ||
package lila.search | ||
package ingestor | ||
|
||
import cats.effect.* | ||
import cats.syntax.all.* | ||
import mongo4cats.database.MongoDatabase | ||
import org.typelevel.log4cats.LoggerFactory | ||
|
||
class Ingestors( | ||
val forum: Ingestor, | ||
val study: Ingestor, | ||
val game: Ingestor, | ||
val team: Ingestor | ||
): | ||
def run(): IO[Unit] = | ||
List(forum.watch, team.watch, study.watch, game.watch).parSequence_ | ||
|
||
object Ingestors: | ||
|
||
def apply( | ||
lichess: MongoDatabase[IO], | ||
study: MongoDatabase[IO], | ||
local: MongoDatabase[IO], | ||
store: KVStore, | ||
elastic: ESClient[IO], | ||
config: IngestorConfig | ||
)(using LoggerFactory[IO]): IO[Ingestors] = | ||
( | ||
ForumRepo(lichess, config.forum), | ||
StudyRepo(study, local, config.study), | ||
GameRepo(lichess, config.game), | ||
TeamRepo(lichess, config.team) | ||
).mapN: (forums, studies, games, teams) => | ||
new Ingestors( | ||
Ingestor(Index.Forum, forums, store, elastic, config.forum.startAt), | ||
Ingestor(Index.Study, studies, store, elastic, config.study.startAt), | ||
Ingestor(Index.Game, games, store, elastic, config.game.startAt), | ||
Ingestor(Index.Team, teams, store, elastic, config.team.startAt) | ||
) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file was deleted.
Oops, something went wrong.