Store vacuum.lastTime as seconds, not milliseconds

Also drop the default pref, since this is just internal state
This commit is contained in:
Dan Stillman 2026-04-13 12:38:02 -04:00
parent f20eb5b566
commit 56ef61e45b
3 changed files with 5 additions and 5 deletions

View file

@ -951,8 +951,9 @@ Zotero.DBConnection.prototype.vacuum = async function ({ force } = {}) {
// Check time threshold
let lastVacuum = Zotero.Prefs.get('vacuum.lastTime') || 0;
let intervalDays = Zotero.Prefs.get('vacuum.interval') || 14;
let intervalMs = intervalDays * 24 * 60 * 60 * 1000;
if ((Date.now() - lastVacuum) < intervalMs) {
let intervalSeconds = intervalDays * 24 * 60 * 60;
let nowSeconds = Math.floor(Date.now() / 1000);
if ((nowSeconds - lastVacuum) < intervalSeconds) {
Zotero.debug("Database was vacuumed recently -- skipping");
return false;
}
@ -1021,7 +1022,7 @@ Zotero.DBConnection.prototype.vacuum = async function ({ force } = {}) {
// Atomic swap
await IOUtils.move(tmpFile, this._dbPath);
Zotero.Prefs.set('vacuum.lastTime', Date.now());
Zotero.Prefs.set('vacuum.lastTime', Math.floor(Date.now() / 1000));
Zotero.debug("Vacuumed database in " + (new Date() - t) + " ms");
return true;

View file

@ -68,7 +68,6 @@ pref("extensions.zotero.feeds.defaultCleanupUnreadAfter", 30);
pref("extensions.zotero.backup.numBackups", 2);
pref("extensions.zotero.backup.interval", 1440);
pref("extensions.zotero.vacuum.lastTime", 0);
pref("extensions.zotero.vacuum.interval", 14); // days
pref("extensions.zotero.vacuum.freelistThreshold", 10); // percentage of free pages to trigger

View file

@ -450,7 +450,7 @@ describe("Zotero.DB", function () {
});
it("should skip vacuum when recently vacuumed", async function () {
Zotero.Prefs.set('vacuum.lastTime', Date.now());
Zotero.Prefs.set('vacuum.lastTime', Math.floor(Date.now() / 1000));
let result = await Zotero.DB.vacuum();
assert.isFalse(result);
Zotero.Prefs.clear('vacuum.lastTime');