fix the pending async count logging. also, use the same connection as sync
fix the pending async count logging. also, use the same connection as sync
and async. We don't actually use the syncConnection as such anymore, but if
we did, we would want to be using the same connection anyways.
--- a/modules/databind.js
+++ b/modules/databind.js
@@ -44,16 +44,17 @@ const Cu = Components.utils;
Cu.import("resource://gloda/modules/log4moz.js");
function DatabindCallback(aDatabind, aCallbackThis, aCallback, aOneShot) {
this._databind = aDatabind;
this._callbackThis = aCallbackThis;
this._callback = aCallback;
this._oneShot = aOneShot;
+ this._databind._datastore._pendingAsyncStatements++;
}
DatabindCallback.prototype = {
handleResult: function (aResultSet) {
let rows = [];
let rowResult;
let getVariant = this._databind._datastore._getVariant;
while (rowResult = aResultSet.getNextRow()) {
let row = {};
--- a/modules/datastore.js
+++ b/modules/datastore.js
@@ -90,16 +90,17 @@ MessagesByMessageIdCallback.prototype =
this.callback.call(this.callbackThis, this.results);
}
};
let PCH_LOG = Log4Moz.Service.getLogger("gloda.ds.pch");
function PostCommitHandler(aCallbacks) {
this.callbacks = aCallbacks;
+ GlodaDatastore._pendingAsyncStatements++;
}
PostCommitHandler.prototype = {
handleResult: function gloda_ds_pch_handleResult(aResultSet) {
},
handleError: function gloda_ds_pch_handleError(aError) {
PCH_LOG.error("database error:" + aError)
@@ -742,17 +743,17 @@ var GlodaDatastore = {
this._log.debug("Migration completed.");
}
}
// Handle corrupt databases, other oddities
// ... in the future. for now, let us die
}
this.syncConnection = dbConnection;
- this.asyncConnection = dbService.openUnsharedDatabase(dbFile);
+ this.asyncConnection = dbConnection;
this._log.debug("Initializing folder mappings.");
this._getAllFolderMappings();
// we need to figure out the next id's for all of the tables where we
// manage that.
this._log.debug("Populating managed id counters.");
this._populateAttributeDefManagedId();
this._populateConversationManagedId();
@@ -780,35 +781,33 @@ var GlodaDatastore = {
// been closed out.
this._commitTransaction();
}
let datastore = this;
function finish_cleanup() {
datastore._cleanupAsyncStatements();
- datastore._log.info("Closing async connection");
+ datastore._cleanupSyncStatements();
+ datastore._log.info("Closing db connection");
datastore.asyncConnection.close();
datastore.asyncConnection = null;
-
- datastore._cleanupSyncStatements();
- datastore._log.info("Closing sync connection");
- datastore.syncConnection.close();
datastore.syncConnection = null;
if (aCallback) {
aCallback.call(aCallbackThis);
}
}
if (this._pendingAsyncStatements) {
this._pendingAsyncCompletedListener = finish_cleanup;
return false;
}
else {
+ this._log.debug("There are no pending async statements, finishing now.");
aCallback = null;
finish_cleanup();
return true;
}
},
/**
* Create our database; basically a wrapper around _createSchema.
--- a/modules/indexer.js
+++ b/modules/indexer.js
@@ -315,19 +315,23 @@ var GlodaIndexer = {
getService(Ci.nsIPrefService);
let branch = prefService.getBranch("mailnews.database.global.indexer");
let eventDrivenEnabled = true; // default
if (branch.prefHasUserValue("enabled"))
eventDrivenEnabled = branch.getBoolPref("enabled");
this.enabled = eventDrivenEnabled;
},
+ /**
+ * @returns true on full and immediate shutdown, false if we need to pend on
+ * something asynchronous.
+ */
_shutdown: function gloda_index_shutdown(aUrlListener) {
if (!this.enabled)
- return;
+ return true;
this._log.info("Shutting Down");
this.suppressIndexing = true;
this._indexerLeaveFolder(); // nop if we aren't "in" a folder
this.enabled = false;
// if the datastore can't stop immediately, it will call the provided