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:
Eike Kettner 2020-05-24 13:28:21 +02:00
parent 4e49c78e72
commit 1dde43e092
2 changed files with 7 additions and 3 deletions

View File

@ -119,8 +119,9 @@ object CreateItem {
private def findExisting[F[_]: Sync]: Task[F, ProcessItemArgs, Option[ItemData]] =
Task { ctx =>
val fileMetaIds = ctx.args.files.map(_.fileMetaId).toSet
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.")
else ().pure[F]
@ -130,8 +131,11 @@ object CreateItem {
ctx.logger.warn(s"Removed ${ht.sum} items with same attachments")
else ().pure[F]
rms <- OptionT(
//load attachments but only those mentioned in the task's arguments
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)
orig <- rms.traverse(a =>

View File

@ -287,7 +287,7 @@ object QItem {
n <- store.transact(RItem.deleteByIdAndCollective(itemId, collective))
} 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 AC = RAttachment.Columns
val q =