[gnome-documents] all: add a queue for sparql select queries
- From: Cosimo Cecchi <cosimoc src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [gnome-documents] all: add a queue for sparql select queries
- Date: Fri, 11 Nov 2011 17:38:01 +0000 (UTC)
commit d6404414c7a12f0313d69ab5af30bcf1633f4e34
Author: Cosimo Cecchi <cosimoc gnome org>
Date: Tue Nov 8 20:36:58 2011 -0500
all: add a queue for sparql select queries
TrackerSparqlConnection doesn't really like performing another
concurrent query while the first one hasn't yet returned, so add a
little queue to order the query requests with.
This dramatically improves smoothness while refreshing the model.
src/application.js | 1 +
src/changeMonitor.js | 2 +-
src/collections.js | 2 +-
src/documents.js | 7 ++-----
src/global.js | 1 +
src/offsetController.js | 6 +++++-
src/trackerController.js | 45 ++++++++++++++++++++++++++++++++++++++++++---
7 files changed, 53 insertions(+), 11 deletions(-)
---
diff --git a/src/application.js b/src/application.js
index b4a617f..a5bd8f1 100644
--- a/src/application.js
+++ b/src/application.js
@@ -144,6 +144,7 @@ Application.prototype = {
this.quit();
}
+ Global.connectionQueue = new TrackerController.TrackerConnectionQueue();
Global.sourceManager = new Sources.SourceManager();
Global.searchMatchManager = new Searchbar.SearchMatchManager();
Global.searchTypeManager = new Searchbar.SearchTypeManager();
diff --git a/src/changeMonitor.js b/src/changeMonitor.js
index 6f85ce6..3276908 100644
--- a/src/changeMonitor.js
+++ b/src/changeMonitor.js
@@ -109,7 +109,7 @@ TrackerChangeMonitor.prototype = {
_updateIterator: function(event, isDelete) {
// we're only interested in the resource URN, as we will query for
// the item properties again, but we still want to compress deletes and inserts
- Global.connection.query_async(
+ Global.connectionQueue.add(
('SELECT tracker:uri(%d) tracker:uri(%d) {}').format(event[1], event[2]),
null, Lang.bind(this,
function(object, res) {
diff --git a/src/collections.js b/src/collections.js
index 4afae10..b951e6d 100644
--- a/src/collections.js
+++ b/src/collections.js
@@ -103,7 +103,7 @@ CollectionManager.prototype = {
_refreshCollections: function() {
this._currentQuery = Global.queryBuilder.buildCollectionsQuery();
- Global.connection.query_async(this._currentQuery.sparql, null, Lang.bind(this,
+ Global.connectionQueue.add(this._currentQuery.sparql, null, Lang.bind(this,
function(object, res) {
try {
let cursor = object.query_finish(res);
diff --git a/src/documents.js b/src/documents.js
index 424697e..f10bee5 100644
--- a/src/documents.js
+++ b/src/documents.js
@@ -82,7 +82,7 @@ DocCommon.prototype = {
refresh: function() {
let query = Global.queryBuilder.buildSingleQuery(this.id);
- Global.connection.query_async(query.sparql, null, Lang.bind(this,
+ Global.connectionQueue.add(query.sparql, null, Lang.bind(this,
function(object, res) {
let cursor = null;
@@ -576,7 +576,7 @@ DocumentManager.prototype = {
_onDocumentCreated: function(urn) {
let query = Global.queryBuilder.buildSingleQuery(urn);
- Global.connection.query_async(query.sparql, null, Lang.bind(this,
+ Global.connectionQueue.add(query.sparql, null, Lang.bind(this,
function(object, res) {
let cursor = null;
@@ -688,9 +688,6 @@ DocumentModel.prototype = {
doc.title, doc.author,
doc.pixbuf, doc.mtime);
}));
-
- while (Gtk.events_pending())
- Gtk.main_iteration();
},
documentRemoved: function(doc) {
diff --git a/src/global.js b/src/global.js
index 029121e..52053dd 100644
--- a/src/global.js
+++ b/src/global.js
@@ -22,6 +22,7 @@
let application = null;
let categoryManager = null;
let connection = null;
+let connectionQueue = null;
let documentManager = null;
let errorHandler = null;
let goaClient = null;
diff --git a/src/offsetController.js b/src/offsetController.js
index 3c5e7cf..5160225 100644
--- a/src/offsetController.js
+++ b/src/offsetController.js
@@ -20,10 +20,14 @@
*/
const Lang = imports.lang;
+const Mainloop = imports.mainloop;
const Signals = imports.signals;
const Global = imports.global;
+const Gio = imports.gi.Gio;
+const GLib = imports.gi.GLib;
+
const _OFFSET_STEP = 50;
function OffsetController() {
@@ -46,7 +50,7 @@ OffsetController.prototype = {
resetItemCount: function() {
let query = Global.queryBuilder.buildCountQuery();
- Global.connection.query_async
+ Global.connectionQueue.add
(query.sparql, null, Lang.bind(this,
function(object, res) {
let cursor = null;
diff --git a/src/trackerController.js b/src/trackerController.js
index 67697a5..80f34f3 100644
--- a/src/trackerController.js
+++ b/src/trackerController.js
@@ -30,9 +30,49 @@ const Query = imports.query;
const Utils = imports.utils;
const Gio = imports.gi.Gio;
+const GLib = imports.gi.GLib;
const MINER_REFRESH_TIMEOUT = 60; /* seconds */
+function TrackerConnectionQueue() {
+ this._init();
+}
+
+TrackerConnectionQueue.prototype = {
+ _init: function() {
+ this._queue = [];
+ this._running = false;
+ },
+
+ add: function(query, cancellable, callback) {
+ let params = { query: query,
+ cancellable: cancellable,
+ callback: callback };
+ this._queue.push(params);
+
+ this._checkQueue();
+ },
+
+ _checkQueue: function() {
+ if (this._running)
+ return;
+
+ if (!this._queue.length)
+ return;
+
+ let params = this._queue.shift();
+ this._running = true;
+ Global.connection.query_async(params.query, params.cancellable,
+ Lang.bind(this, this._queueCollector, params));
+ },
+
+ _queueCollector: function(connection, res, params) {
+ params.callback(connection, res);
+ this._running = false;
+ this._checkQueue();
+ }
+};
+
function TrackerController() {
this._init();
}
@@ -43,7 +83,6 @@ TrackerController.prototype = {
this._cancellable = new Gio.Cancellable();
this._queryQueued = false;
this._querying = false;
-
// startup a refresh of the gdocs cache
this._miner = new GDataMiner.GDataMiner();
this._refreshMinerNow();
@@ -143,8 +182,8 @@ TrackerController.prototype = {
this._cancellable.reset();
this._setQueryStatus(true);
- Global.connection.query_async(this._currentQuery.sparql,
- this._cancellable, Lang.bind(this, this._onQueryExecuted));
+ Global.connectionQueue.add(this._currentQuery.sparql,
+ this._cancellable, Lang.bind(this, this._onQueryExecuted));
},
_refresh: function() {
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]