mirror of
https://github.com/TheAnachronism/docspell.git
synced 2025-06-22 02:18:26 +00:00
Store item based proposals in separate table
Classifier don't work on each attachment, but on all. So the results must not be stored at an attachment. This reverts some previous changes to put the classifier results for item entities into its own table.
This commit is contained in:
@ -84,7 +84,6 @@ object AttachmentPageCount {
|
||||
Nil,
|
||||
MetaProposalList.empty,
|
||||
md.pageCount.some,
|
||||
None,
|
||||
None
|
||||
)
|
||||
)
|
||||
|
@ -2,9 +2,9 @@ package docspell.joex.process
|
||||
|
||||
import cats.effect.Sync
|
||||
import cats.implicits._
|
||||
|
||||
import docspell.common._
|
||||
import docspell.joex.scheduler.Task
|
||||
import docspell.store.AddResult
|
||||
import docspell.store.records._
|
||||
|
||||
/** Saves the proposals in the database
|
||||
@ -13,17 +13,36 @@ object SaveProposals {
|
||||
|
||||
def apply[F[_]: Sync](data: ItemData): Task[F, ProcessItemArgs, ItemData] =
|
||||
Task { ctx =>
|
||||
ctx.logger.info("Storing proposals") *>
|
||||
data.metas
|
||||
for {
|
||||
_ <- ctx.logger.info("Storing proposals")
|
||||
_ <- data.metas
|
||||
.traverse(rm =>
|
||||
ctx.logger.debug(
|
||||
s"Storing attachment proposals: ${rm.proposals} and ${data.classifyProposals}"
|
||||
) *>
|
||||
ctx.store.transact(
|
||||
RAttachmentMeta
|
||||
.updateProposals(rm.id, rm.proposals, data.classifyProposals)
|
||||
)
|
||||
s"Storing attachment proposals: ${rm.proposals}"
|
||||
) *> ctx.store.transact(RAttachmentMeta.updateProposals(rm.id, rm.proposals))
|
||||
)
|
||||
.map(_ => data)
|
||||
_ <- data.classifyProposals match {
|
||||
case Some(clp) =>
|
||||
val itemId = data.item.id
|
||||
ctx.logger.debug(s"Storing classifier proposals: $clp") *>
|
||||
ctx.store
|
||||
.add(
|
||||
RItemProposal.createNew(itemId, clp),
|
||||
RItemProposal.exists(itemId)
|
||||
)
|
||||
.flatMap({
|
||||
case AddResult.EntityExists(_) =>
|
||||
ctx.store.transact(RItemProposal.updateProposals(itemId, clp))
|
||||
case AddResult.Failure(ex) =>
|
||||
ctx.logger
|
||||
.warn(s"Could not store classifier proposals: ${ex.getMessage}") *>
|
||||
0.pure[F]
|
||||
case AddResult.Success =>
|
||||
1.pure[F]
|
||||
})
|
||||
case None =>
|
||||
0.pure[F]
|
||||
}
|
||||
} yield data
|
||||
}
|
||||
}
|
||||
|
Reference in New Issue
Block a user