Skip pdf conversion if a converted file exists

For images the conversion also returns the extracted text. If this
would have failed to be saved, it is extracted in the following
text-extraction step.
This commit is contained in:
Eike Kettner
2020-10-02 00:20:30 +02:00
parent b6f23b038a
commit d4354b8b49
4 changed files with 40 additions and 4 deletions

View File

@ -44,6 +44,9 @@ case class Column(name: String, ns: String = "", alias: String = "") {
def isNot[A: Put](value: A): Fragment =
f ++ fr"<> $value"
def isNot(c: Column): Fragment =
f ++ fr"<>" ++ c.f
def isNull: Fragment =
f ++ fr"is null"

View File

@ -46,6 +46,9 @@ object RAttachmentMeta {
def exists(attachId: Ident): ConnectionIO[Boolean] =
selectCount(id, table, id.is(attachId)).query[Int].unique.map(_ > 0)
def findById(attachId: Ident): ConnectionIO[Option[RAttachmentMeta]] =
selectSimple(all, table, id.is(attachId)).query[RAttachmentMeta].option
def upsert(v: RAttachmentMeta): ConnectionIO[Int] =
for {
n0 <- update(v)

View File

@ -48,6 +48,21 @@ object RAttachmentSource {
.unique
.map(_ > 0)
def isConverted(attachId: Ident): ConnectionIO[Boolean] = {
val sId = Columns.id.prefix("s")
val sFile = Columns.fileId.prefix("s")
val aId = RAttachment.Columns.id.prefix("a")
val aFile = RAttachment.Columns.fileId.prefix("a")
val from = table ++ fr"s INNER JOIN" ++
RAttachment.table ++ fr"a ON" ++ aId.is(sId)
selectCount(aId, from, and(aId.is(attachId), aFile.isNot(sFile)))
.query[Int]
.unique
.map(_ > 0)
}
def delete(attachId: Ident): ConnectionIO[Int] =
deleteFrom(table, id.is(attachId)).update.run