Provide endpoints to submit tasks to re-generate previews

The scaling factor can be given in the config file. When this changes,
images can be regenerated via POSTing to certain endpoints. It is
possible to regenerate just one attachment preview or all within a
collective.
This commit is contained in:
Eike Kettner
2020-11-09 01:18:48 +01:00
parent 6037b54959
commit f4e50c5229
20 changed files with 218 additions and 38 deletions

View File

@ -26,9 +26,9 @@ object QAttachment {
Stream
.evalSeq(store.transact(findPreview))
.map(_.fileId.id)
.evalTap(_ => store.transact(RAttachmentPreview.delete(attachId)))
.flatMap(store.bitpeace.delete)
.map(flag => if (flag) 1 else 0)
.evalMap(_ => store.transact(RAttachmentPreview.delete(attachId)))
.compile
.foldMonoid
}

View File

@ -231,6 +231,30 @@ object RAttachment {
def findItemId(attachId: Ident): ConnectionIO[Option[Ident]] =
selectSimple(Seq(itemId), table, id.is(attachId)).query[Ident].option
def findAll(
coll: Option[Ident],
chunkSize: Int
): Stream[ConnectionIO, RAttachment] = {
val aItem = Columns.itemId.prefix("a")
val iId = RItem.Columns.id.prefix("i")
val iColl = RItem.Columns.cid.prefix("i")
val cols = all.map(_.prefix("a"))
coll match {
case Some(cid) =>
val join = table ++ fr"a INNER JOIN" ++ RItem.table ++ fr"i ON" ++ iId.is(aItem)
val cond = iColl.is(cid)
selectSimple(cols, join, cond)
.query[RAttachment]
.streamWithChunkSize(chunkSize)
case None =>
selectSimple(cols, table, Fragment.empty)
.query[RAttachment]
.streamWithChunkSize(chunkSize)
}
}
def findWithoutPreview(
coll: Option[Ident],
chunkSize: Int