mirror of
https://github.com/TheAnachronism/docspell.git
synced 2025-06-06 15:15:58 +00:00
Only process attachments in task arguments
When files are added to an item, the attachments already present must not be "re-processed".
This commit is contained in:
parent
4e49c78e72
commit
1dde43e092
@ -119,8 +119,9 @@ object CreateItem {
|
|||||||
|
|
||||||
private def findExisting[F[_]: Sync]: Task[F, ProcessItemArgs, Option[ItemData]] =
|
private def findExisting[F[_]: Sync]: Task[F, ProcessItemArgs, Option[ItemData]] =
|
||||||
Task { ctx =>
|
Task { ctx =>
|
||||||
|
val fileMetaIds = ctx.args.files.map(_.fileMetaId).toSet
|
||||||
for {
|
for {
|
||||||
cand <- ctx.store.transact(QItem.findByFileIds(ctx.args.files.map(_.fileMetaId)))
|
cand <- ctx.store.transact(QItem.findByFileIds(fileMetaIds.toSeq))
|
||||||
_ <-
|
_ <-
|
||||||
if (cand.nonEmpty) ctx.logger.warn("Found existing item with these files.")
|
if (cand.nonEmpty) ctx.logger.warn("Found existing item with these files.")
|
||||||
else ().pure[F]
|
else ().pure[F]
|
||||||
@ -130,8 +131,11 @@ object CreateItem {
|
|||||||
ctx.logger.warn(s"Removed ${ht.sum} items with same attachments")
|
ctx.logger.warn(s"Removed ${ht.sum} items with same attachments")
|
||||||
else ().pure[F]
|
else ().pure[F]
|
||||||
rms <- OptionT(
|
rms <- OptionT(
|
||||||
|
//load attachments but only those mentioned in the task's arguments
|
||||||
cand.headOption.traverse(ri =>
|
cand.headOption.traverse(ri =>
|
||||||
ctx.store.transact(RAttachment.findByItemAndCollective(ri.id, ri.cid))
|
ctx.store
|
||||||
|
.transact(RAttachment.findByItemAndCollective(ri.id, ri.cid))
|
||||||
|
.map(_.filter(r => fileMetaIds.contains(r.fileId)))
|
||||||
)
|
)
|
||||||
).getOrElse(Vector.empty)
|
).getOrElse(Vector.empty)
|
||||||
orig <- rms.traverse(a =>
|
orig <- rms.traverse(a =>
|
||||||
|
@ -287,7 +287,7 @@ object QItem {
|
|||||||
n <- store.transact(RItem.deleteByIdAndCollective(itemId, collective))
|
n <- store.transact(RItem.deleteByIdAndCollective(itemId, collective))
|
||||||
} yield tn + rn + n
|
} yield tn + rn + n
|
||||||
|
|
||||||
def findByFileIds(fileMetaIds: List[Ident]): ConnectionIO[Vector[RItem]] = {
|
def findByFileIds(fileMetaIds: Seq[Ident]): ConnectionIO[Vector[RItem]] = {
|
||||||
val IC = RItem.Columns
|
val IC = RItem.Columns
|
||||||
val AC = RAttachment.Columns
|
val AC = RAttachment.Columns
|
||||||
val q =
|
val q =
|
||||||
|
Loading…
x
Reference in New Issue
Block a user