Bug 511965 - Delay Places syncs after results updates, r=sdwilsh

This commit is contained in:
Marco Bonardo 2009-08-21 22:36:59 +02:00
parent eaf7e3c442
commit 3f51d0e4e0

View File

@ -222,7 +222,7 @@ nsPlacesDBFlush.prototype = {
this._timer = this._newTimer();
// We need to sync now
this._flushWithQueries([kQuerySyncPlacesId, kQuerySyncHistoryVisitsId]);
this._delayedFlushWithQueries([kQuerySyncPlacesId, kQuerySyncHistoryVisitsId]);
},
onItemAdded: function(aItemId, aParentId, aIndex)
@ -231,14 +231,14 @@ nsPlacesDBFlush.prototype = {
// least amount of queries as possible here for performance reasons.
if (!this._inBatchMode &&
this._bs.getItemType(aItemId) == this._bs.TYPE_BOOKMARK)
this._flushWithQueries([kQuerySyncPlacesId]);
this._delayedFlushWithQueries([kQuerySyncPlacesId]);
},
onItemChanged: function DBFlush_onItemChanged(aItemId, aProperty,
aIsAnnotationProperty, aValue)
{
if (!this._inBatchMode && aProperty == "uri")
this._flushWithQueries([kQuerySyncPlacesId]);
this._delayedFlushWithQueries([kQuerySyncPlacesId]);
},
onBeforeItemRemoved: function() { },
@ -350,6 +350,22 @@ nsPlacesDBFlush.prototype = {
this._db.executeAsync(statements, statements.length, this);
},
/**
* Enqueues a flush to the main thread, used in observers to avoid flushing
* while the original method is still notifying.
*/
_delayedFlushWithQueries: function DBFlush_delayedflushWithQueries(aQueryNames)
{
let tm = Cc["@mozilla.org/thread-manager;1"].
getService(Ci.nsIThreadManager);
let self = this;
tm.mainThread.dispatch({
run: function() {
self._flushWithQueries(aQueryNames);
}
}, Ci.nsIThread.DISPATCH_NORMAL);
},
/**
* Finalizes all of our mozIStorageStatements so we can properly close the
* database.