mirror of
				https://github.com/TheAnachronism/docspell.git
				synced 2025-11-04 12:30:12 +00:00 
			
		
		
		
	Fix deleting items and attachments to also remove the binary files
This commit is contained in:
		@@ -8,22 +8,22 @@ import doobie.implicits._
 | 
			
		||||
import docspell.common.{Ident, MetaProposalList}
 | 
			
		||||
import docspell.store.Store
 | 
			
		||||
import docspell.store.impl.Implicits._
 | 
			
		||||
import docspell.store.records.{RAttachment, RAttachmentMeta, RItem}
 | 
			
		||||
import docspell.store.records.{RAttachment, RAttachmentMeta, RAttachmentSource, RItem}
 | 
			
		||||
 | 
			
		||||
object QAttachment {
 | 
			
		||||
 | 
			
		||||
  def deleteById[F[_]: Sync](store: Store[F])(attachId: Ident, coll: Ident): F[Int] =
 | 
			
		||||
    for {
 | 
			
		||||
      raOpt <- store.transact(RAttachment.findByIdAndCollective(attachId, coll))
 | 
			
		||||
      n     <- raOpt.traverse(_ => store.transact(RAttachment.delete(attachId)))
 | 
			
		||||
      f <- Stream
 | 
			
		||||
            .emit(raOpt)
 | 
			
		||||
            .unNoneTerminate
 | 
			
		||||
            .map(_.fileId.id)
 | 
			
		||||
      raFile <- store.transact(RAttachment.findByIdAndCollective(attachId, coll)).map(_.map(_.fileId))
 | 
			
		||||
      rsFile <- store.transact(RAttachmentSource.findById(attachId)).map(_.map(_.fileId))
 | 
			
		||||
      n     <- store.transact(RAttachment.delete(attachId))
 | 
			
		||||
      f <- Stream.emits(raFile.toSeq ++ rsFile.toSeq)
 | 
			
		||||
            .map(_.id)
 | 
			
		||||
            .flatMap(store.bitpeace.delete)
 | 
			
		||||
            .map(flag => if (flag) 1 else 0)
 | 
			
		||||
            .compile
 | 
			
		||||
            .last
 | 
			
		||||
    } yield n.getOrElse(0) + f.map(_ => 1).getOrElse(0)
 | 
			
		||||
    } yield n + f.getOrElse(0)
 | 
			
		||||
 | 
			
		||||
  def deleteAttachment[F[_]: Sync](store: Store[F])(ra: RAttachment): F[Int] =
 | 
			
		||||
    for {
 | 
			
		||||
 
 | 
			
		||||
@@ -59,4 +59,6 @@ object RAttachmentSource {
 | 
			
		||||
 | 
			
		||||
    selectSimple(all.map(_.prefix("a")), from, where).query[RAttachmentSource].option
 | 
			
		||||
  }
 | 
			
		||||
 | 
			
		||||
 | 
			
		||||
}
 | 
			
		||||
 
 | 
			
		||||
		Reference in New Issue
	
	Block a user