@@ -2,7 +2,12 @@ package eu.pretix.libpretixsync.sync
22
33import eu.pretix.libpretixsync.api.ApiException
44import eu.pretix.libpretixsync.api.PretixApi
5- import eu.pretix.libpretixsync.db.*
5+ import eu.pretix.libpretixsync.db.Event
6+ import eu.pretix.libpretixsync.db.Order
7+ import eu.pretix.libpretixsync.db.OrderPosition
8+ import eu.pretix.libpretixsync.db.ResourceSyncStatus
9+ import eu.pretix.libpretixsync.db.SubEvent
10+ import eu.pretix.libpretixsync.sqldelight.SyncDatabase
611import eu.pretix.libpretixsync.sync.SyncManager.ProgressFeedback
712import io.requery.BlockingEntityStore
813import io.requery.Persistable
@@ -13,7 +18,7 @@ import org.joda.time.Duration
1318import org.json.JSONException
1419import kotlin.math.max
1520
16- class OrderCleanup (val store : BlockingEntityStore <Persistable >, val fileStorage : FileStorage , val api : PretixApi , val syncCycleId : String , val feedback : ProgressFeedback ? ) {
21+ class OrderCleanup (val db : SyncDatabase , val store : BlockingEntityStore <Persistable >, val fileStorage : FileStorage , val api : PretixApi , val syncCycleId : String , val feedback : ProgressFeedback ? ) {
1722 private var subeventsDeletionDate: MutableMap <Long , Long ?> = HashMap ()
1823 private fun deletionTimeForSubevent (sid : Long , eventSlug : String ): Long? {
1924 if (subeventsDeletionDate.containsKey(sid)) {
@@ -177,13 +182,11 @@ class OrderCleanup(val store: BlockingEntityStore<Persistable>, val fileStorage:
177182 }
178183
179184 fun deleteOldPdfImages () {
180- store.delete(CachedPdfImage ::class .java).where(
181- CachedPdfImage .ORDERPOSITION_ID .notIn(store.select(OrderPosition .SERVER_ID ).from(OrderPosition ::class .java))
182- )
185+ db.cachedPdfImageQueries.deleteOld()
183186 for (filename in fileStorage.listFiles { _, s -> s.startsWith(" pdfimage_" ) }) {
184187 val namebase = filename.split(" \\ ." .toRegex()).toTypedArray()[0 ]
185188 val etag = namebase.split(" _" .toRegex()).toTypedArray()[1 ]
186- if (store.count( CachedPdfImage :: class .java).where( CachedPdfImage . ETAG .eq( etag)).get().value() == 0 ) {
189+ if (db.cachedPdfImageQueries.countEtag( etag).executeAsOne() == 0L ) {
187190 fileStorage.delete(filename)
188191 }
189192 }
0 commit comments