[gnome-documents] query: simplify code



commit e994df6853ba3252b2a61b9556bdb07611f82b35
Author: Cosimo Cecchi <cosimoc gnome org>
Date:   Tue Jun 5 15:49:14 2012 -0400

    query: simplify code
    
    No actual changes here

 src/documents.js |    2 +-
 src/query.js     |   37 ++++++++++++++++---------------------
 2 files changed, 17 insertions(+), 22 deletions(-)
---
diff --git a/src/documents.js b/src/documents.js
index 84a3433..e122718 100644
--- a/src/documents.js
+++ b/src/documents.js
@@ -53,7 +53,7 @@ const SingleItemJob = new Lang.Class({
     run: function(flags, callback) {
         this._callback = callback;
 
-        let query = Global.queryBuilder.buildSingleQuery(this._urn, flags);
+        let query = Global.queryBuilder.buildSingleQuery(flags, this._urn);
         Global.connectionQueue.add(query.sparql, null, Lang.bind(this,
             function(object, res) {
                 try {
diff --git a/src/query.js b/src/query.js
index 6e7e2e5..bf1e962 100644
--- a/src/query.js
+++ b/src/query.js
@@ -136,27 +136,28 @@ const QueryBuilder = new Lang.Class({
     },
 
     _buildQueryInternal: function(global, flags) {
-        let globalSparql =
+        let whereSparql =
             'WHERE { ?urn a rdfs:Resource ' +
             this._buildOptional();
 
-        if (global) {
-            if ((flags & QueryFlags.UNFILTERED) == 0)
-                globalSparql +=
+        if ((flags & QueryFlags.UNFILTERED) == 0) {
+            if (global)
+                whereSparql +=
                     Global.searchCategoryManager.getWhere() +
-                    Global.collectionManager.getWhere() +
-                    this._buildFilterString();
+                    Global.collectionManager.getWhere();
+
+            whereSparql += this._buildFilterString();
+        }
+
+        whereSparql += ' }';
+
+        let tailSparql = '';
 
-            globalSparql +=
-                ' } ' +
+        if (global) {
+            tailSparql +=
                 'ORDER BY DESC (?mtime)' +
                 ('LIMIT %d OFFSET %d').format(Global.offsetController.getOffsetStep(),
                                               Global.offsetController.getOffset());
-        } else {
-            if ((flags & QueryFlags.UNFILTERED) == 0)
-                globalSparql += this._buildFilterString();
-
-            globalSparql += ' }';
         }
 
         let sparql =
@@ -172,18 +173,12 @@ const QueryBuilder = new Lang.Class({
             'nie:dataSource(?urn) ' + // resource URN
             '( EXISTS { ?urn nao:hasTag nao:predefined-tag-favorite } ) ' + // favorite
             '( EXISTS { ?urn nco:contributor ?contributor FILTER ( ?contributor != ?creator ) } ) ' + // shared
-            globalSparql;
+            whereSparql + tailSparql;
 
         return sparql;
     },
 
-    buildSingleQuery: function() {
-        let resource = arguments[0];
-        let flags = QueryFlags.NONE;
-
-        if (arguments.length == 2)
-            flags = arguments[1];
-
+    buildSingleQuery: function(flags, resource) {
         let sparql = this._buildQueryInternal(false, flags);
         sparql = sparql.replace('?urn', '<' + resource + '>', 'g');
 



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