From 1e3726d573b740af2ab6fb41d8ab9ba708bb5315 Mon Sep 17 00:00:00 2001 From: Raphael Michel Date: Thu, 23 Jul 2026 18:09:25 +0200 Subject: [PATCH] Run PRAGMA optimize --- .../java/eu/pretix/libpretixsync/sync/SyncManager.java | 7 ++++++- .../postgres/eu/pretix/libpretixsync/sqldelight/compat.sq | 3 +++ .../sqlite/eu/pretix/libpretixsync/sqldelight/compat.sq | 4 ++++ 3 files changed, 13 insertions(+), 1 deletion(-) diff --git a/libpretixsync/src/main/java/eu/pretix/libpretixsync/sync/SyncManager.java b/libpretixsync/src/main/java/eu/pretix/libpretixsync/sync/SyncManager.java index 49e97204..3462514c 100644 --- a/libpretixsync/src/main/java/eu/pretix/libpretixsync/sync/SyncManager.java +++ b/libpretixsync/src/main/java/eu/pretix/libpretixsync/sync/SyncManager.java @@ -476,7 +476,12 @@ protected void downloadData(ProgressFeedback feedback, Boolean skip_orders, Stri } } - + // After a download, table statistics might be worth re-evaluating for faster query + // execution. On SQLite, this will run PRAGMA optimize; which will be a no-op if there + // haven't been a lot of changes. On PostgreSQL, ANALYZE is a bit more expensive, so + // we'll see whether it is worth it. + // See recommendations on https://sqlite.org/lang_analyze.html + db.getCompatQueries().analyzeAfterSync(); } catch (DeviceAccessRevokedException e) { db.getCompatQueries().truncateCheckIn(); db.getCompatQueries().truncateOrderPosition(); diff --git a/libpretixsync/src/main/sqldelight/postgres/eu/pretix/libpretixsync/sqldelight/compat.sq b/libpretixsync/src/main/sqldelight/postgres/eu/pretix/libpretixsync/sqldelight/compat.sq index 0c840176..eba159d3 100644 --- a/libpretixsync/src/main/sqldelight/postgres/eu/pretix/libpretixsync/sqldelight/compat.sq +++ b/libpretixsync/src/main/sqldelight/postgres/eu/pretix/libpretixsync/sqldelight/compat.sq @@ -127,3 +127,6 @@ UPDATE QueuedOrder SET locked = TRUE WHERE id = ?; + +analyzeAfterSync: +ANALYZE SKIP_LOCKED; \ No newline at end of file diff --git a/libpretixsync/src/main/sqldelight/sqlite/eu/pretix/libpretixsync/sqldelight/compat.sq b/libpretixsync/src/main/sqldelight/sqlite/eu/pretix/libpretixsync/sqldelight/compat.sq index 02277eeb..bb5ba1c0 100644 --- a/libpretixsync/src/main/sqldelight/sqlite/eu/pretix/libpretixsync/sqldelight/compat.sq +++ b/libpretixsync/src/main/sqldelight/sqlite/eu/pretix/libpretixsync/sqldelight/compat.sq @@ -127,3 +127,7 @@ UPDATE QueuedOrder SET locked = 1 WHERE id = ?; + + +analyzeAfterSync: +PRAGMA optimize; \ No newline at end of file