mirror of
https://github.com/TheAnachronism/docspell.git
synced 2025-06-05 22:55:58 +00:00
Fix deleting attachments (again)
This commit is contained in:
parent
d937e0501a
commit
661cc3e65f
@ -15,21 +15,25 @@ 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 {
|
||||||
raFile <- store.transact(RAttachment.findByIdAndCollective(attachId, coll)).map(_.map(_.fileId))
|
raFile <- store.transact(RAttachment.findByIdAndCollective(attachId, coll)).map(_.map(_.fileId))
|
||||||
rsFile <- store.transact(RAttachmentSource.findById(attachId)).map(_.map(_.fileId))
|
rsFile <- store.transact(RAttachmentSource.findByIdAndCollective(attachId, coll)).map(_.map(_.fileId))
|
||||||
n <- store.transact(RAttachment.delete(attachId))
|
n <- store.transact(RAttachment.delete(attachId))
|
||||||
f <- Stream.emits(raFile.toSeq ++ rsFile.toSeq)
|
f <- Stream.emits(raFile.toSeq ++ rsFile.toSeq)
|
||||||
.map(_.id)
|
.map(_.id)
|
||||||
.flatMap(store.bitpeace.delete)
|
.flatMap(store.bitpeace.delete)
|
||||||
.map(flag => if (flag) 1 else 0)
|
.map(flag => if (flag) 1 else 0)
|
||||||
.compile
|
.compile
|
||||||
.last
|
.foldMonoid
|
||||||
} yield n + f.getOrElse(0)
|
} yield n + f
|
||||||
|
|
||||||
def deleteAttachment[F[_]: Sync](store: Store[F])(ra: RAttachment): F[Int] =
|
def deleteAttachment[F[_]: Sync](store: Store[F])(ra: RAttachment): F[Int] =
|
||||||
for {
|
for {
|
||||||
|
s <- store.transact(RAttachmentSource.findById(ra.id))
|
||||||
n <- store.transact(RAttachment.delete(ra.id))
|
n <- store.transact(RAttachment.delete(ra.id))
|
||||||
f <- Stream.emit(ra.fileId.id).flatMap(store.bitpeace.delete).compile.last
|
f <- Stream.emits(ra.fileId.id +: s.map(_.fileId.id).toSeq).
|
||||||
} yield n + f.map(_ => 1).getOrElse(0)
|
flatMap(store.bitpeace.delete).
|
||||||
|
map(flag => if (flag) 1 else 0).
|
||||||
|
compile.foldMonoid
|
||||||
|
} yield n + f
|
||||||
|
|
||||||
def deleteItemAttachments[F[_]: Sync](store: Store[F])(itemId: Ident, coll: Ident): F[Int] =
|
def deleteItemAttachments[F[_]: Sync](store: Store[F])(itemId: Ident, coll: Ident): F[Int] =
|
||||||
for {
|
for {
|
||||||
|
Loading…
x
Reference in New Issue
Block a user