From 3a23293e58b9869ab723c7929619790c7b80b7d7 Mon Sep 17 00:00:00 2001 From: Thanh Le Date: Mon, 17 Jun 2024 09:12:04 +0700 Subject: [PATCH] Include update & delete event to our change stream --- modules/ingestor/src/main/scala/ingestor.forum.scala | 7 ++++--- 1 file changed, 4 insertions(+), 3 deletions(-) diff --git a/modules/ingestor/src/main/scala/ingestor.forum.scala b/modules/ingestor/src/main/scala/ingestor.forum.scala index 1468994e..9da9b6f0 100644 --- a/modules/ingestor/src/main/scala/ingestor.forum.scala +++ b/modules/ingestor/src/main/scala/ingestor.forum.scala @@ -3,7 +3,7 @@ package ingestor import cats.effect.IO import cats.syntax.all.* -import com.mongodb.client.model.changestream.OperationType +import com.mongodb.client.model.changestream.OperationType.* import lila.search.spec.ForumSource import mongo4cats.bson.Document import mongo4cats.database.MongoDatabase @@ -22,7 +22,8 @@ object ForumIngestor: private val topicProjection = Projection.include(List("_id", "name")) - private val eventFilter = Filter.in("operationType", List("replace", "insert")) + val interestedOperations = List(DELETE, INSERT, UPDATE, REPLACE).map(_.getValue) + private val eventFilter = Filter.in("operationType", interestedOperations) private val eventProjection = Projection.include( List( "documentKey._id", @@ -124,5 +125,5 @@ object ForumIngestor: private def topicId = event.fullDocument.flatMap(_.getString("topicId")) private def isDelete: Boolean = - event.operationType == OperationType.DELETE || + event.operationType == DELETE || event.fullDocument.flatMap(_.get("erasedAt")).isDefined