Apparently the dummy transaction hasn't been necessary since 2007 or so
https://bugzilla.mozilla.org/show_bug.cgi?id=380345
This commit is contained in:
parent
e7d7d2a943
commit
50a0b2d36c
|
@ -23,7 +23,8 @@
|
|||
***** END LICENSE BLOCK *****
|
||||
*/
|
||||
|
||||
// Exclusive locking mode (default) prevents access to Zotero database while Firefox is open.
|
||||
// Exclusive locking mode (default) prevents access to Zotero database while Zotero is open
|
||||
// and speeds up DB access (http://www.sqlite.org/pragma.html#pragma_locking_mode).
|
||||
// Normal mode is more convenient for development, but risks database corruption, particularly if
|
||||
// the same database is accessed simultaneously by multiple Zotero instances.
|
||||
const DB_LOCK_EXCLUSIVE = true;
|
||||
|
@ -793,7 +794,6 @@ Zotero.DBConnection.prototype.checkException = function (e) {
|
|||
|
||||
Zotero.DBConnection.prototype.closeDatabase = function () {
|
||||
if(this._connection) {
|
||||
this.stopDummyStatement();
|
||||
this._connection.close();
|
||||
return true;
|
||||
}
|
||||
|
@ -875,14 +875,10 @@ Zotero.DBConnection.prototype.backupDatabase = function (suffix) {
|
|||
|
||||
// Turn off DB locking before backup and reenable after, since otherwise
|
||||
// the lock is lost
|
||||
var hadDummyStatement = !!this._dummyStatement;
|
||||
try {
|
||||
if (DB_LOCK_EXCLUSIVE) {
|
||||
this.query("PRAGMA locking_mode=NORMAL");
|
||||
}
|
||||
if (hadDummyStatement) {
|
||||
this.stopDummyStatement();
|
||||
}
|
||||
|
||||
var store = Components.classes["@mozilla.org/storage/service;1"].
|
||||
getService(Components.interfaces.mozIStorageService);
|
||||
|
@ -897,9 +893,6 @@ Zotero.DBConnection.prototype.backupDatabase = function (suffix) {
|
|||
if (DB_LOCK_EXCLUSIVE) {
|
||||
this.query("PRAGMA locking_mode=EXCLUSIVE");
|
||||
}
|
||||
if (hadDummyStatement) {
|
||||
this.startDummyStatement();
|
||||
}
|
||||
}
|
||||
|
||||
// Opened database files can't be moved on Windows, so we have to skip
|
||||
|
@ -968,71 +961,6 @@ Zotero.DBConnection.prototype.backupDatabase = function (suffix) {
|
|||
}
|
||||
|
||||
|
||||
/*
|
||||
* Keep the SQLite shared cache live between transactions with a dummy statement,
|
||||
* which speeds up DB access dramatically (at least on Windows and Linux--OS X
|
||||
* seems to be much faster already, perhaps due to its own disk cache)
|
||||
*
|
||||
* This is the same technique used by Mozilla code. The one downside is that it
|
||||
* prevents schema changes, so this is called after schema updating. If the
|
||||
* schema really needs to be updated at another point, use stopDummyStatement().
|
||||
*
|
||||
* See http://developer.mozilla.org/en/docs/Storage:Performance for more info.
|
||||
*/
|
||||
Zotero.DBConnection.prototype.startDummyStatement = function () {
|
||||
try {
|
||||
if (!this._dummyConnection) {
|
||||
this._debug("Opening database '" + this._dbName + "' for dummy statement");
|
||||
// Get the storage service
|
||||
var store = Components.classes["@mozilla.org/storage/service;1"].
|
||||
getService(Components.interfaces.mozIStorageService);
|
||||
var file = Zotero.getZoteroDatabase(this._dbName);
|
||||
this._dummyConnection = store.openDatabase(file);
|
||||
}
|
||||
|
||||
if (this._dummyStatement) {
|
||||
Zotero.debug("Dummy statement is already open");
|
||||
return;
|
||||
}
|
||||
|
||||
Zotero.debug("Initializing dummy statement for '" + this._dbName + "'");
|
||||
|
||||
var sql = "CREATE TABLE IF NOT EXISTS zoteroDummyTable (id INTEGER PRIMARY KEY)";
|
||||
this._dummyConnection.executeSimpleSQL(sql);
|
||||
|
||||
sql = "INSERT OR IGNORE INTO zoteroDummyTable VALUES (1)";
|
||||
this._dummyConnection.executeSimpleSQL(sql);
|
||||
|
||||
sql = "SELECT id FROM zoteroDummyTable LIMIT 1"
|
||||
this._dummyStatement = this._dummyConnection.createStatement(sql)
|
||||
this._dummyStatement.executeStep()
|
||||
|
||||
}
|
||||
catch (e) {
|
||||
Components.utils.reportError(e);
|
||||
Zotero.debug(e);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
/*
|
||||
* Stop the dummy statement temporarily to allow for schema changess
|
||||
*
|
||||
* The statement needs to be started again or performance will suffer.
|
||||
*/
|
||||
Zotero.DBConnection.prototype.stopDummyStatement = function () {
|
||||
if (!this._dummyStatement) {
|
||||
return;
|
||||
}
|
||||
|
||||
Zotero.debug("Stopping dummy statement for '" + this._dbName + "'");
|
||||
this._dummyStatement.finalize();
|
||||
this._dummyConnection.close();
|
||||
delete this._dummyConnection;
|
||||
delete this._dummyStatement;
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Determine the necessary data type for SQLite parameter binding
|
||||
*
|
||||
|
|
|
@ -640,8 +640,6 @@ Components.utils.import("resource://gre/modules/Services.jsm");
|
|||
}
|
||||
}
|
||||
|
||||
Zotero.DB.startDummyStatement();
|
||||
|
||||
// Populate combined tables for custom types and fields -- this is likely temporary
|
||||
if (!upgraded && !updated) {
|
||||
Zotero.Schema.updateCustomTables();
|
||||
|
|
Loading…
Reference in New Issue
Block a user