From 56ef61e45b965ef970d2da1f69858beeabb3ab44 Mon Sep 17 00:00:00 2001 From: Dan Stillman Date: Mon, 13 Apr 2026 12:38:02 -0400 Subject: [PATCH] Store vacuum.lastTime as seconds, not milliseconds Also drop the default pref, since this is just internal state --- chrome/content/zotero/xpcom/db.js | 7 ++++--- defaults/preferences/zotero.js | 1 - test/tests/dbTest.js | 2 +- 3 files changed, 5 insertions(+), 5 deletions(-) diff --git a/chrome/content/zotero/xpcom/db.js b/chrome/content/zotero/xpcom/db.js index 841179a702..246f8c93cf 100644 --- a/chrome/content/zotero/xpcom/db.js +++ b/chrome/content/zotero/xpcom/db.js @@ -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; diff --git a/defaults/preferences/zotero.js b/defaults/preferences/zotero.js index fedb6edd69..79a4abfb98 100644 --- a/defaults/preferences/zotero.js +++ b/defaults/preferences/zotero.js @@ -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 diff --git a/test/tests/dbTest.js b/test/tests/dbTest.js index 13689f1787..7dae666351 100644 --- a/test/tests/dbTest.js +++ b/test/tests/dbTest.js @@ -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');