[gnome-documents] all: code cleanups



commit 5c44b87551de0f02e982cb2810307610674227c9
Author: Cosimo Cecchi <cosimoc gnome org>
Date:   Fri Aug 26 14:49:11 2011 -0400

    all: code cleanups

 src/docFactory.js   |    8 ++++++--
 src/trackerUtils.js |   13 +++++++++----
 2 files changed, 15 insertions(+), 6 deletions(-)
---
diff --git a/src/docFactory.js b/src/docFactory.js
index 23f8cda..3027011 100644
--- a/src/docFactory.js
+++ b/src/docFactory.js
@@ -65,14 +65,18 @@ DocCommon.prototype = {
 
     _refresh: function() {
         let sparql = Global.queryBuilder.buildSingleQuery(this.urn);
+
         Global.connection.query_async(sparql, null, Lang.bind(this,
             function(object, res) {
+                let cursor = null;
+
                 try {
-                    let cursor = object.query_finish(res);
+                    cursor = object.query_finish(res);
                     cursor.next_async(null, Lang.bind(this,
                         function(object, res) {
                             let valid = object.next_finish(res);
-                            this._populateFromCursor(object);
+                            if (valid)
+                                this._populateFromCursor(object);
                         }));
                 } catch (e) {
                     log('Unable to refresh file information: ' + e.toString());
diff --git a/src/trackerUtils.js b/src/trackerUtils.js
index aa12b73..dd1a77d 100644
--- a/src/trackerUtils.js
+++ b/src/trackerUtils.js
@@ -28,8 +28,10 @@ function sourceIdFromResourceUrn(resourceUrn, callback) {
     if(resourceUrn[0] != '<')
         resourceUrn = '<' + resourceUrn + '>';
 
+    let sparql = ('SELECT ?id WHERE { %s a nie:DataSource; nao:identifier ?id }').format(resourceUrn);
+
     Global.connection.query_async
-        (('SELECT ?id WHERE { %s a nie:DataSource; nao:identifier ?id }').format(resourceUrn), null,
+        (sparql, null,
          function(object, res) {
              let cursor = null;
              try {
@@ -59,8 +61,10 @@ function sourceIdFromResourceUrn(resourceUrn, callback) {
 }
 
 function resourceUrnFromSourceId(sourceId, callback) {
+    let sparql = ('SELECT ?urn WHERE { ?urn a nie:DataSource; nao:identifier \"goa:documents:%s\" }').format(sourceId);
+
     Global.connection.query_async
-        (('SELECT ?urn WHERE { ?urn a nie:DataSource; nao:identifier \"goa:documents:%s\" }').format(sourceId), null,
+        (sparql, null,
          function(object, res) {
              let cursor = null;
              let urn = '';
@@ -96,8 +100,9 @@ function resourceUrnFromSourceId(sourceId, callback) {
 }
 
 function setFavorite(urn, isFavorite, callback) {
-    Global.connection.update_async(
-        ('%s { <%s> nao:hasTag nao:predefined-tag-favorite }').format((isFavorite ? 'INSERT OR REPLACE' : 'DELETE'), urn),
+    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,
         function(object, res) {
             try {



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