mirror of
https://github.com/zotero/zotero.git
synced 2026-08-28 05:25:31 +00:00
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:
parent
85e1cbc75c
commit
7243648ed7
1 changed files with 15 additions and 6 deletions
|
|
@ -37,6 +37,7 @@ Zotero.DBConnection = function (dbNameOrPath) {
|
||||||
}
|
}
|
||||||
|
|
||||||
this.MAX_BOUND_PARAMETERS = 999;
|
this.MAX_BOUND_PARAMETERS = 999;
|
||||||
|
this.IDLE_OBSERVER_SECONDS = 300;
|
||||||
this.DB_CORRUPTION_STRINGS = [
|
this.DB_CORRUPTION_STRINGS = [
|
||||||
"database disk image is malformed",
|
"database disk image is malformed",
|
||||||
"2152857611"
|
"2152857611"
|
||||||
|
|
@ -1672,12 +1673,20 @@ Zotero.DBConnection.prototype._getConnectionAsync = async function () {
|
||||||
}
|
}
|
||||||
|
|
||||||
// Register idle observer for DB backup
|
// Register idle observer for DB backup
|
||||||
Zotero.Schema.schemaUpdatePromise.then(() => {
|
if (!this._idleObserverScheduled) {
|
||||||
Zotero.debug("Initializing DB backup idle observer");
|
this._idleObserverScheduled = true;
|
||||||
var idleService = Components.classes["@mozilla.org/widget/useridleservice;1"]
|
Zotero.Schema.schemaUpdatePromise.then(() => {
|
||||||
.getService(Components.interfaces.nsIUserIdleService);
|
// The database can be closed permanently while this is pending
|
||||||
idleService.addIdleObserver(this, 300);
|
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
|
// Re-load any extensions loaded via loadExtension(), which are registered per connection and
|
||||||
|
|
|
||||||
Loading…
Add table
Reference in a new issue