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