Make sure the empty-trash task is started for all collectives

This commit is contained in:
eikek
2021-08-14 20:10:42 +02:00
parent 50706c3d6d
commit 27fd7a5867
6 changed files with 55 additions and 15 deletions

View File

@ -8,6 +8,7 @@ package docspell.store.records
import cats.data.NonEmptyList
import cats.implicits._
import fs2.Stream
import docspell.common._
import docspell.store.qb.DSL._
@ -62,6 +63,23 @@ object REmptyTrashSetting {
sql.query[REmptyTrashSetting].option
}
def findForAllCollectives(
default: CalEvent,
chunkSize: Int
): Stream[ConnectionIO, REmptyTrashSetting] = {
val c = RCollective.as("c")
val e = REmptyTrashSetting.as("e")
val sql = run(
select(
c.id.s,
coalesce(e.schedule.s, const(default)).s,
coalesce(e.created.s, c.created.s).s
),
from(c).leftJoin(e, e.cid === c.id)
)
sql.query[REmptyTrashSetting].streamWithChunkSize(chunkSize)
}
def delete(coll: Ident): ConnectionIO[Int] =
DML.delete(T, T.cid === coll)