mirror of
				https://github.com/TheAnachronism/docspell.git
				synced 2025-10-30 13:20:11 +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:
		| @@ -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 => | ||||
|   | ||||
| @@ -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 = | ||||
|   | ||||
		Reference in New Issue
	
	Block a user