Skip to content

Commit

Permalink
Log failed to index posts
Browse files Browse the repository at this point in the history
  • Loading branch information
lenguyenthanh committed Jun 17, 2024
1 parent a7d445a commit 0faedad
Showing 1 changed file with 11 additions and 4 deletions.
15 changes: 11 additions & 4 deletions modules/ingestor/src/main/scala/ingestor.forum.scala
Original file line number Diff line number Diff line change
Expand Up @@ -105,10 +105,17 @@ object ForumIngestor:
extension (events: List[ChangeStreamDocument[Document]])
private def toSources: IO[List[(String, ForumSource)]] =
val topicIds = events.flatMap(_.topicId).distinct
topicByIds(topicIds).map: topicMap =>
events.flatten: event =>
(event.id, event.topicId, event.fullDocument).flatMapN: (id, topicId, doc) =>
doc.toSource(topicName = topicMap.get(topicId)).map(id -> _)
topicByIds(topicIds)
.flatMap: topicMap =>
events
.traverse: event =>
(event.id, event.topicId, event.fullDocument)
.flatMapN: (id, topicId, doc) =>
doc.toSource(topicName = topicMap.get(topicId)).map(id -> _)
.match
case Some(value) => value.some.pure[IO]
case _ => info"failed to convert document to source: $event".as(none)
.map(_.flatten)

extension (doc: Document)
private def toSource(topicName: Option[String]): Option[ForumSource] =
Expand Down

0 comments on commit 0faedad

Please sign in to comment.