mirror of
https://github.com/TheAnachronism/docspell.git
synced 2025-06-21 18:08:25 +00:00
Fix attachment positions
It worked for new items, because the implicit offset was 0. when adding archives to existing items, there are already attachments and the new attachments are added to the end. This won't work if files are added concurrently, because there is no quick and reliable way to determine the offset then.
This commit is contained in:
@ -101,4 +101,6 @@ case class Column(name: String, ns: String = "", alias: String = "") {
|
||||
def asc: Fragment =
|
||||
f ++ fr"asc"
|
||||
|
||||
def max: Fragment =
|
||||
fr"MAX(" ++ f ++ fr")"
|
||||
}
|
||||
|
@ -38,8 +38,10 @@ object RAttachment {
|
||||
fr"${v.id},${v.itemId},${v.fileId.id},${v.position},${v.created},${v.name}"
|
||||
).update.run
|
||||
|
||||
def countOnItem(id: Ident): ConnectionIO[Int] =
|
||||
selectCount(itemId, table, itemId.is(id)).query[Int].unique
|
||||
def nextPosition(id: Ident): ConnectionIO[Int] =
|
||||
for {
|
||||
max <- selectSimple(position.max, table, itemId.is(id)).query[Option[Int]].unique
|
||||
} yield max.map(_ + 1).getOrElse(0)
|
||||
|
||||
def updateFileIdAndName(
|
||||
attachId: Ident,
|
||||
|
Reference in New Issue
Block a user