Register the DB backup idle observer only once per connection

The observer was added on every open with no matching removal, so each
reopen left behind another registration that received its own idle
notification. On macOS, where the periodic backup closes and reopens the
connection, the registrations accumulated and multiplied the work done
on each idle.

Addresses #6027
This commit is contained in:
Dan Stillman 2026-08-21 16:06:24 -04:00
parent 85e1cbc75c
commit 7243648ed7

View file

@ -37,6 +37,7 @@ Zotero.DBConnection = function (dbNameOrPath) {
}
this.MAX_BOUND_PARAMETERS = 999;
this.IDLE_OBSERVER_SECONDS = 300;
this.DB_CORRUPTION_STRINGS = [
"database disk image is malformed",
"2152857611"
@ -1672,12 +1673,20 @@ Zotero.DBConnection.prototype._getConnectionAsync = async function () {
}
// Register idle observer for DB backup
Zotero.Schema.schemaUpdatePromise.then(() => {
Zotero.debug("Initializing DB backup idle observer");
var idleService = Components.classes["@mozilla.org/widget/useridleservice;1"]
.getService(Components.interfaces.nsIUserIdleService);
idleService.addIdleObserver(this, 300);
});
if (!this._idleObserverScheduled) {
this._idleObserverScheduled = true;
Zotero.Schema.schemaUpdatePromise.then(() => {
// The database can be closed permanently while this is pending
if (this._connection === false) {
return;
}
Zotero.debug("Initializing DB backup idle observer");
var idleService = Components.classes["@mozilla.org/widget/useridleservice;1"]
.getService(Components.interfaces.nsIUserIdleService);
idleService.addIdleObserver(this, this.IDLE_OBSERVER_SECONDS);
this._idleObserverRegistered = true;
});
}
}
// Re-load any extensions loaded via loadExtension(), which are registered per connection and