Create tasks to generate all previews

There is a task to generate preview images per attachment. It can
either add them (if not present yet) or overwrite them (e.g. some
config has changed).

There is a task that selects all attachments without previews and
submits a task to create it. This is submitted on start automatically
to generate previews for all existing attachments.
This commit is contained in:
Eike Kettner
2020-11-08 23:46:02 +01:00
parent eede194352
commit 709848244c
9 changed files with 299 additions and 9 deletions

View File

@ -17,6 +17,22 @@ import doobie.implicits._
object QAttachment {
private[this] val logger = org.log4s.getLogger
def deletePreview[F[_]: Sync](store: Store[F])(attachId: Ident): F[Int] = {
val findPreview =
for {
rp <- RAttachmentPreview.findById(attachId)
} yield rp.toSeq
Stream
.evalSeq(store.transact(findPreview))
.map(_.fileId.id)
.flatMap(store.bitpeace.delete)
.map(flag => if (flag) 1 else 0)
.evalMap(_ => store.transact(RAttachmentPreview.delete(attachId)))
.compile
.foldMonoid
}
/** Deletes an attachment, its related source and meta data records.
* It will only delete an related archive file, if this is the last
* attachment in that archive.

View File

@ -231,6 +231,38 @@ object RAttachment {
def findItemId(attachId: Ident): ConnectionIO[Option[Ident]] =
selectSimple(Seq(itemId), table, id.is(attachId)).query[Ident].option
def findWithoutPreview(
coll: Option[Ident],
chunkSize: Int
): Stream[ConnectionIO, RAttachment] = {
val aId = Columns.id.prefix("a")
val aItem = Columns.itemId.prefix("a")
val pId = RAttachmentPreview.Columns.id.prefix("p")
val iId = RItem.Columns.id.prefix("i")
val iColl = RItem.Columns.cid.prefix("i")
val cols = all.map(_.prefix("a"))
val baseJoin =
table ++ fr"a LEFT OUTER JOIN" ++
RAttachmentPreview.table ++ fr"p ON" ++ pId.is(aId)
val baseCond =
Seq(pId.isNull)
coll match {
case Some(cid) =>
val join = baseJoin ++ fr"INNER JOIN" ++ RItem.table ++ fr"i ON" ++ iId.is(aItem)
val cond = and(baseCond ++ Seq(iColl.is(cid)))
selectSimple(cols, join, cond)
.query[RAttachment]
.streamWithChunkSize(chunkSize)
case None =>
selectSimple(cols, baseJoin, and(baseCond))
.query[RAttachment]
.streamWithChunkSize(chunkSize)
}
}
def findNonConvertedPdf(
coll: Option[Ident],
chunkSize: Int