feat(db): VACUUM after retention and an Optimize button in Backup modal

SQLite DELETE marks pages free but doesn't shrink the file, so the
new retention job would keep DBs at their bloated size forever without
a follow-up VACUUM. Add db.vacuum() that runs PRAGMA-free VACUUM and
reports size_before/size_after/elapsed so callers can surface results.

The retention job now calls vacuum() automatically when it deleted at
least 1000 rows. Threshold avoids the multi-second VACUUM cost on quiet
days. Failure is logged, not raised — a missed VACUUM never crashes
the scheduler.

Power-user override: new "Optimize now" button in the Database Backup
modal triggers VACUUM on demand via POST /api/db/vacuum, alongside a
GET /api/db/size that drives the live "Current size" label. This way
users don't have to wait until 03:30 to reclaim space after the first
big retention pass.

Co-Authored-By: Claude Opus 4.7 <noreply@anthropic.com>
This commit is contained in:
MarekWo
2026-06-07 10:55:23 +02:00
parent 422e7a3b34
commit f72f6d418a
5 changed files with 151 additions and 1 deletions
+12
View File
@@ -1212,6 +1212,18 @@
<div class="spinner-border spinner-border-sm"></div> Loading...
</div>
</div>
<hr class="my-3">
<h6 class="mb-2"><i class="bi bi-arrows-collapse"></i> Optimize database</h6>
<p class="text-muted small mb-2">
Reclaim space freed by message retention. Runs SQLite <code>VACUUM</code>;
readers keep working but writes are paused for a few seconds.
</p>
<div class="d-flex justify-content-between align-items-center">
<button class="btn btn-outline-primary btn-sm" id="vacuumDbBtn" onclick="optimizeDatabase()">
<i class="bi bi-arrows-collapse"></i> Optimize now
</button>
<span id="vacuumDbStatus" class="text-muted small">Current size: …</span>
</div>
</div>
</div>
</div>