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

Async deletion bug fix #1484

Merged
merged 1 commit into from
Sep 21, 2023
Merged
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
Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@
package services.search

import akka.actor.ActorRef
import akka.stream.Materializer
import akka.stream.scaladsl.Source
import play.api.{Configuration, Logger}
import services.data.EventForwarder.{Create, Delete, Update}
import services.data.EventHandler
Expand All @@ -13,7 +15,7 @@ case class IndexingEventHandler @Inject()(
searchIndexer: SearchIndexMediator,
config: Configuration,
@Named("event-forwarder") forwarder: ActorRef
)(implicit ec: ExecutionContext) extends EventHandler {
)(implicit ec: ExecutionContext, mat: Materializer) extends EventHandler {

private val logger = Logger(getClass)

Expand Down Expand Up @@ -46,9 +48,16 @@ case class IndexingEventHandler @Inject()(
// after redirects because the item is still in the search index but not in
// the database.
def handleDelete(ids: String*): Unit = logFailure(ids, ids => Future.successful[Unit] {
ids.grouped(threshold * 2).map { group =>
val deletes = ids.toSeq.grouped(threshold * 2).map { group =>
logger.debug(s"Deleting ID group: ${group.mkString(", ")}")
forwarder ! Delete(group)
concurrent.Await.result(searchIndexer.handle.clearIds(group: _*), timeoutMinutes(ids.size))
searchIndexer.handle.clearIds(group: _*)
}
// This runs all deletes in a synchronous sequence, as opposed to in parallel
val allDone: Future[akka.Done] = Source.fromIterator(() => deletes)
.mapAsync(parallelism = 1)(identity)
.runForeach(identity)

concurrent.Await.result(allDone, timeoutMinutes(ids.size))
})
}
Loading