make tags view more efficient, and only request the tags we are after twisty
authorMark Hammond <mhammond@skippinet.com.au>
Tue, 24 Mar 2009 15:29:13 +1100
branchtwisty
changeset 119 201badf26a8a840c3eee1c70561f451c5594fdd1
parent 118 983858314348eb45baf83f528c3f58fc34065b01
child 120 27c7fce59f31b577af80efdc9658ca755505ac93
push id1
push userroot
push dateWed, 08 Apr 2009 01:46:05 +0000
make tags view more efficient, and only request the tags we are after
client/cloda-completers.js
schema/tags/all/views/all/map.js
schema/tags/all/views/all/reduce.js
--- a/client/cloda-completers.js
+++ b/client/cloda-completers.js
@@ -27,30 +27,29 @@ var ContactCompleter = {
   }
 };
 
 var TagCompleter = {
   type: "tag",
   complete: function(aAutocomplete, aText) {
     console.log("Tag completer firing on", aText);
     Gloda.dbMessages.view("raindrop!tags!all/all", {
+      startkey: aText,
+      endkey: aText + "\u9999",
       success: function(result) {
         var nodes = [];
         if (!result.rows) {
           console.log("Tag completer can't see any tags; db is new?");
           return;
         }
         var tagNames = result.rows[0].value;
         console.log("Tag completer got tag names:", tagNames);
-        var textLength = aText.length;
         tagNames.forEach(function (tagName) {
-          if (tagName.substring(0, textLength) == aText) {
-            var node = $("<div/>")[0];
-            ElementXBL.prototype.addBinding.call(node, "autocomplete.xml#tag-completion");
-            node.setTagName(tagName);
-            nodes.push(node);
-          }
+          var node = $("<div/>")[0];
+          ElementXBL.prototype.addBinding.call(node, "autocomplete.xml#tag-completion");
+          node.setTagName(tagName);
+          nodes.push(node);
         });
         aAutocomplete.haveSomeResults(aText, nodes, TagCompleter, 100);
       }
     });
   }
 };
--- a/schema/tags/all/views/all/map.js
+++ b/schema/tags/all/views/all/map.js
@@ -1,8 +1,8 @@
 function(doc) {
     if (doc.type && doc.type=='anno/tags' && doc.tags) {
         var id = doc._id;
         var emit_id = id.substr(0, id.indexOf('!')) + '!message';
         for (var i = 0; i < doc.tags.length; i++)
-            emit([doc.tags[i], doc.raindrop_seq], emit_id);
+            emit(doc.tags[i], null);
     }
 }
--- a/schema/tags/all/views/all/reduce.js
+++ b/schema/tags/all/views/all/reduce.js
@@ -1,13 +1,13 @@
 function(keys, values, rereduce) {
   var keySet = {}, i, j;
   if (!rereduce) {
     for (i = 0; i < keys.length; i++)
-      keySet[keys[i][0][0]] = true;
+      keySet[keys[i][0]] = true;
   }
   else {
     for (i = 0; i < values.length; i++) {
       var inSet = values[i];
       for (j = 0; j < inSet.length; j++)
         keySet[inSet[j]] = true;
     }
   }