mirror of
https://github.com/TheAnachronism/docspell.git
synced 2025-06-22 02:18:26 +00:00
Add backend operations for re-creating the full-text index
This commit is contained in:
@ -61,7 +61,7 @@ object BackendApp {
|
||||
jobImpl <- OJob(store, joexImpl)
|
||||
itemImpl <- OItem(store, solrFts)
|
||||
itemSearchImpl <- OItemSearch(store)
|
||||
fulltextImpl <- OFulltext(itemSearchImpl, solrFts)
|
||||
fulltextImpl <- OFulltext(itemSearchImpl, solrFts, store, queue)
|
||||
javaEmil =
|
||||
JavaMailEmil(blocker, Settings.defaultSettings.copy(debug = cfg.mailDebug))
|
||||
mailImpl <- OMail(store, javaEmil)
|
||||
|
@ -0,0 +1,90 @@
|
||||
package docspell.backend
|
||||
|
||||
import cats.effect._
|
||||
import cats.implicits._
|
||||
import docspell.common._
|
||||
import docspell.store.records.RJob
|
||||
|
||||
object JobFactory {
|
||||
|
||||
def processItem[F[_]: Sync](
|
||||
args: ProcessItemArgs,
|
||||
account: AccountId,
|
||||
prio: Priority,
|
||||
tracker: Option[Ident]
|
||||
): F[RJob] =
|
||||
for {
|
||||
id <- Ident.randomId[F]
|
||||
now <- Timestamp.current[F]
|
||||
job = RJob.newJob(
|
||||
id,
|
||||
ProcessItemArgs.taskName,
|
||||
account.collective,
|
||||
args,
|
||||
args.makeSubject,
|
||||
now,
|
||||
account.user,
|
||||
prio,
|
||||
tracker
|
||||
)
|
||||
} yield job
|
||||
|
||||
def processItems[F[_]: Sync](
|
||||
args: Vector[ProcessItemArgs],
|
||||
account: AccountId,
|
||||
prio: Priority,
|
||||
tracker: Option[Ident]
|
||||
): F[Vector[RJob]] = {
|
||||
def create(id: Ident, now: Timestamp, arg: ProcessItemArgs): RJob =
|
||||
RJob.newJob(
|
||||
id,
|
||||
ProcessItemArgs.taskName,
|
||||
account.collective,
|
||||
arg,
|
||||
arg.makeSubject,
|
||||
now,
|
||||
account.user,
|
||||
prio,
|
||||
tracker
|
||||
)
|
||||
|
||||
for {
|
||||
id <- Ident.randomId[F]
|
||||
now <- Timestamp.current[F]
|
||||
jobs = args.map(a => create(id, now, a))
|
||||
} yield jobs
|
||||
}
|
||||
|
||||
def reIndexAll[F[_]: Sync]: F[RJob] =
|
||||
for {
|
||||
id <- Ident.randomId[F]
|
||||
now <- Timestamp.current[F]
|
||||
} yield RJob.newJob(
|
||||
id,
|
||||
ReIndexTaskArgs.taskName,
|
||||
DocspellSystem.taskGroup,
|
||||
ReIndexTaskArgs(None),
|
||||
s"Recreate full-text index",
|
||||
now,
|
||||
DocspellSystem.taskGroup,
|
||||
Priority.Low,
|
||||
Some(DocspellSystem.migrationTaskTracker)
|
||||
)
|
||||
|
||||
def reIndex[F[_]: Sync](account: AccountId): F[RJob] =
|
||||
for {
|
||||
id <- Ident.randomId[F]
|
||||
now <- Timestamp.current[F]
|
||||
args = ReIndexTaskArgs(Some(account.collective))
|
||||
} yield RJob.newJob(
|
||||
id,
|
||||
ReIndexTaskArgs.taskName,
|
||||
account.collective,
|
||||
args,
|
||||
s"Recreate full-text index",
|
||||
now,
|
||||
account.user,
|
||||
Priority.Low,
|
||||
Some(ReIndexTaskArgs.tracker(args))
|
||||
)
|
||||
}
|
@ -5,6 +5,10 @@ import cats.implicits._
|
||||
import fs2.Stream
|
||||
import docspell.common._
|
||||
import docspell.ftsclient._
|
||||
import docspell.backend.JobFactory
|
||||
import docspell.store.Store
|
||||
import docspell.store.records.RJob
|
||||
import docspell.store.queue.JobQueue
|
||||
import OItemSearch.{Batch, ListItem, ListItemWithTags, Query}
|
||||
|
||||
trait OFulltext[F[_]] {
|
||||
@ -22,7 +26,7 @@ trait OFulltext[F[_]] {
|
||||
/** Clears the full-text index for the given collective and starts a
|
||||
* task indexing all their data.
|
||||
*/
|
||||
def reindexCollective(collective: Ident): F[Unit]
|
||||
def reindexCollective(account: AccountId): F[Unit]
|
||||
}
|
||||
|
||||
object OFulltext {
|
||||
@ -32,12 +36,27 @@ object OFulltext {
|
||||
|
||||
def apply[F[_]: Effect](
|
||||
itemSearch: OItemSearch[F],
|
||||
fts: FtsClient[F]
|
||||
fts: FtsClient[F],
|
||||
store: Store[F],
|
||||
queue: JobQueue[F]
|
||||
): Resource[F, OFulltext[F]] =
|
||||
Resource.pure[F, OFulltext[F]](new OFulltext[F] {
|
||||
def reindexAll: F[Unit] = ???
|
||||
def reindexAll: F[Unit] =
|
||||
for {
|
||||
job <- JobFactory.reIndexAll[F]
|
||||
_ <- queue.insertIfNew(job)
|
||||
} yield ()
|
||||
|
||||
def reindexCollective(collective: Ident): F[Unit] = ???
|
||||
def reindexCollective(account: AccountId): F[Unit] =
|
||||
for {
|
||||
exist <- store.transact(
|
||||
RJob.findNonFinalByTracker(DocspellSystem.migrationTaskTracker)
|
||||
)
|
||||
job <- JobFactory.reIndex(account)
|
||||
_ <-
|
||||
if (exist.isDefined) ().pure[F]
|
||||
else queue.insertIfNew(job)
|
||||
} yield ()
|
||||
|
||||
def findItems(q: Query, ftsQ: String, batch: Batch): F[Vector[ListItem]] =
|
||||
findItemsFts(q, ftsQ, batch, itemSearch.findItems)
|
||||
|
@ -5,7 +5,7 @@ import cats.Functor
|
||||
import cats.data.{EitherT, OptionT}
|
||||
import cats.effect._
|
||||
import cats.implicits._
|
||||
import docspell.backend.Config
|
||||
import docspell.backend.{Config, JobFactory}
|
||||
import fs2.Stream
|
||||
import docspell.common._
|
||||
import docspell.common.syntax.all._
|
||||
@ -203,26 +203,7 @@ object OUpload {
|
||||
account: AccountId,
|
||||
prio: Priority,
|
||||
tracker: Option[Ident]
|
||||
): F[Vector[RJob]] = {
|
||||
def create(id: Ident, now: Timestamp, arg: ProcessItemArgs): RJob =
|
||||
RJob.newJob(
|
||||
id,
|
||||
ProcessItemArgs.taskName,
|
||||
account.collective,
|
||||
arg,
|
||||
arg.makeSubject,
|
||||
now,
|
||||
account.user,
|
||||
prio,
|
||||
tracker
|
||||
)
|
||||
|
||||
for {
|
||||
id <- Ident.randomId[F]
|
||||
now <- Timestamp.current[F]
|
||||
jobs = args.map(a => create(id, now, a))
|
||||
} yield jobs
|
||||
|
||||
}
|
||||
): F[Vector[RJob]] =
|
||||
JobFactory.processItems[F](args, account, prio, tracker)
|
||||
})
|
||||
}
|
||||
|
Reference in New Issue
Block a user