[gnome-documents] connection: add methods to queue updates on the connection object



commit cc75b85373808a726fcc60883ba0753763682c9f
Author: Cosimo Cecchi <cosimoc gnome org>
Date:   Fri Nov 11 16:32:09 2011 -0500

    connection: add methods to queue updates on the connection object
    
    Make updates go through the same connection queue.

 src/trackerController.js |   41 ++++++++++++++++++++++++++++++++++++++---
 src/trackerUtils.js      |    3 +--
 2 files changed, 39 insertions(+), 5 deletions(-)
---
diff --git a/src/trackerController.js b/src/trackerController.js
index b9802f5..d05a414 100644
--- a/src/trackerController.js
+++ b/src/trackerController.js
@@ -34,6 +34,12 @@ const GLib = imports.gi.GLib;
 
 const MINER_REFRESH_TIMEOUT = 60; /* seconds */
 
+const QueryType = {
+    SELECT: 0,
+    UPDATE: 1,
+    UPDATE_BLANK: 2
+};
+
 function TrackerConnectionQueue() {
     this._init();
 }
@@ -47,7 +53,28 @@ TrackerConnectionQueue.prototype = {
     add: function(query, cancellable, callback) {
         let params = { query: query,
                        cancellable: cancellable,
-                       callback: callback };
+                       callback: callback,
+                       queryType: QueryType.SELECT };
+        this._queue.push(params);
+
+        this._checkQueue();
+    },
+
+    update: function(query, cancellable, callback) {
+        let params = { query: query,
+                       cancellable: cancellable,
+                       callback: callback,
+                       queryType: QueryType.UPDATE };
+        this._queue.push(params);
+
+        this._checkQueue();
+    },
+
+    updateBlank: function(query, cancellable, callback) {
+        let params = { query: query,
+                       cancellable: cancellable,
+                       callback: callback,
+                       queryType: QueryType.UPDATE_BLANK };
         this._queue.push(params);
 
         this._checkQueue();
@@ -62,8 +89,16 @@ TrackerConnectionQueue.prototype = {
 
         let params = this._queue.shift();
         this._running = true;
-        Global.connection.query_async(params.query, params.cancellable,
-                                      Lang.bind(this, this._queueCollector, params));
+
+        if (params.queryType == QueryType.SELECT)
+            Global.connection.query_async(params.query, params.cancellable,
+                                          Lang.bind(this, this._queueCollector, params));
+        else if (params.queryType == QueryType.UPDATE)
+            Global.connection.update_async(params.query, GLib.PRIORITY_DEFAULT, params.cancellable,
+                                           Lang.bind(this, this._queueCollector, params));
+        else if (params.queryType == QueryType.UPDATE_BLANK)
+            Global.connection.update_blank_async(params.query, GLib.PRIORITY_DEFAULT, params.cancellable,
+                                                 Lang.bind(this, this._queueCollector, params));
     },
 
     _queueCollector: function(connection, res, params) {
diff --git a/src/trackerUtils.js b/src/trackerUtils.js
index 6152e52..73e43a1 100644
--- a/src/trackerUtils.js
+++ b/src/trackerUtils.js
@@ -26,8 +26,7 @@ const Global = imports.global;
 function setFavorite(urn, isFavorite, callback) {
     let sparql = ('%s { <%s> nao:hasTag nao:predefined-tag-favorite }').format((isFavorite ? 'INSERT OR REPLACE' : 'DELETE'), urn);
 
-    Global.connection.update_async(sparql,
-        GLib.PRIORITY_DEFAULT, null,
+    Global.connectionQueue.update(sparql, null,
         function(object, res) {
             try {
                 object.update_finish(res);



[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]