[gnome-documents] tracker-controller: don't schedule two concurrent queries on refresh
- From: Cosimo Cecchi <cosimoc src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [gnome-documents] tracker-controller: don't schedule two concurrent queries on refresh
- Date: Wed, 2 Nov 2011 03:25:42 +0000 (UTC)
commit c5921df4f053eecd0fcd267c74fec52cee5a9b2d
Author: Cosimo Cecchi <cosimoc gnome org>
Date: Mon Oct 31 15:35:47 2011 -0400
tracker-controller: don't schedule two concurrent queries on refresh
In case we refresh when a query is pending, we need to make sure to
cancel the previous query and wait for it to return, if we want the
results in the stores to be aligned with the last query.
src/trackerController.js | 25 ++++++++++++++++++++++---
1 files changed, 22 insertions(+), 3 deletions(-)
---
diff --git a/src/trackerController.js b/src/trackerController.js
index 7e2fb3d..50ce50a 100644
--- a/src/trackerController.js
+++ b/src/trackerController.js
@@ -29,6 +29,8 @@ const Global = imports.global;
const Query = imports.query;
const Utils = imports.utils;
+const Gio = imports.gi.Gio;
+
const MINER_REFRESH_TIMEOUT = 60; /* seconds */
function TrackerController() {
@@ -38,6 +40,8 @@ function TrackerController() {
TrackerController.prototype = {
_init: function() {
this._currentQuery = null;
+ this._cancellable = new Gio.Cancellable();
+ this._queryQueued = false;
this._querying = false;
// startup a refresh of the gdocs cache
@@ -94,6 +98,11 @@ TrackerController.prototype = {
if (exception)
Global.errorHandler.addQueryError(exception);
+
+ if (this._queryQueued) {
+ this._queryQueued = false;
+ this._refresh();
+ }
},
_onCursorNext: function(cursor, res) {
@@ -113,13 +122,13 @@ TrackerController.prototype = {
}
Global.documentManager.addDocumentFromCursor(cursor);
- cursor.next_async(null, Lang.bind(this, this._onCursorNext));
+ cursor.next_async(this._cancellable, Lang.bind(this, this._onCursorNext));
},
_onQueryExecuted: function(object, res) {
try {
let cursor = object.query_finish(res);
- cursor.next_async(null, Lang.bind(this, this._onCursorNext));
+ cursor.next_async(this._cancellable, Lang.bind(this, this._onCursorNext));
} catch (e) {
this._onQueryFinished(e);
}
@@ -127,11 +136,21 @@ TrackerController.prototype = {
_performCurrentQuery: function() {
this._currentQuery = Global.queryBuilder.buildGlobalQuery();
+ this._cancellable.reset();
+
+ this._setQueryStatus(true);
Global.connection.query_async(this._currentQuery.sparql,
- null, Lang.bind(this, this._onQueryExecuted));
+ this._cancellable, Lang.bind(this, this._onQueryExecuted));
},
_refresh: function() {
+ if (this.getQueryStatus()) {
+ this._cancellable.cancel();
+ this._queryQueued = true;
+
+ return;
+ }
+
this._setQueryStatus(true);
Global.documentManager.clear();
this._offsetController.resetItemCount();
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]