mirror of
https://github.com/TheAnachronism/docspell.git
synced 2025-06-21 09:58:26 +00:00
Fix global re-index task to re-create the schema
Otherwise new instances could not be re-indexed.
This commit is contained in:
@ -2,7 +2,8 @@ package docspell.joex.fts
|
||||
|
||||
import cats.effect._
|
||||
import cats.data.{Kleisli, NonEmptyList}
|
||||
import cats.{FlatMap, Semigroup}
|
||||
import cats.{ApplicativeError, FlatMap, Semigroup}
|
||||
import cats.implicits._
|
||||
import docspell.common._
|
||||
import docspell.ftsclient._
|
||||
import docspell.joex.scheduler.Context
|
||||
@ -24,6 +25,9 @@ object FtsWork {
|
||||
|
||||
// some tasks
|
||||
|
||||
def log[F[_]](f: Logger[F] => F[Unit]): FtsWork[F] =
|
||||
FtsWork(ctx => f(ctx.logger))
|
||||
|
||||
def initialize[F[_]]: FtsWork[F] =
|
||||
FtsWork(_.fts.initialize)
|
||||
|
||||
@ -74,6 +78,11 @@ object FtsWork {
|
||||
def ++(mn: FtsWork[F])(implicit ev: FlatMap[F]): FtsWork[F] =
|
||||
all(mt, mn)
|
||||
|
||||
def recoverWith(
|
||||
other: FtsWork[F]
|
||||
)(implicit ev: ApplicativeError[F, Throwable]): FtsWork[F] =
|
||||
Kleisli(ctx => mt.run(ctx).onError({ case _ => other.run(ctx) }))
|
||||
|
||||
def forContext(
|
||||
cfg: Config.FullTextSearch,
|
||||
fts: FtsClient[F]
|
||||
|
@ -21,13 +21,34 @@ object ReIndexTask {
|
||||
.log[F, Args](_.info(s"Running full-text re-index now"))
|
||||
.flatMap(_ =>
|
||||
Task(ctx =>
|
||||
(FtsWork.clearIndex(ctx.args.collective) ++ FtsWork.insertAll[F](
|
||||
ctx.args.collective
|
||||
)).forContext(cfg, fts).run(ctx)
|
||||
(clearData[F](ctx.args.collective) ++
|
||||
FtsWork.log[F](_.info("Inserting data from database")) ++
|
||||
FtsWork.insertAll[F](
|
||||
ctx.args.collective
|
||||
)).forContext(cfg, fts).run(ctx)
|
||||
)
|
||||
)
|
||||
|
||||
def onCancel[F[_]: Sync]: Task[F, Args, Unit] =
|
||||
Task.log[F, Args](_.warn("Cancelling full-text re-index task"))
|
||||
|
||||
private def clearData[F[_]: ConcurrentEffect](collective: Option[Ident]): FtsWork[F] =
|
||||
FtsWork.log[F](_.info("Clearing index data")) ++
|
||||
(collective match {
|
||||
case Some(_) =>
|
||||
FtsWork
|
||||
.clearIndex(collective)
|
||||
.recoverWith(
|
||||
FtsWork.log[F](_.info("Clearing data failed. Continue re-indexing."))
|
||||
)
|
||||
|
||||
case None =>
|
||||
FtsWork
|
||||
.clearIndex(None)
|
||||
.recoverWith(
|
||||
FtsWork.log[F](_.info("Clearing data failed. Continue re-indexing."))
|
||||
) ++
|
||||
FtsWork.log[F](_.info("Running index initialize")) ++
|
||||
FtsWork.initialize[F]
|
||||
})
|
||||
}
|
||||
|
Reference in New Issue
Block a user