couchdb-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From fdman...@apache.org
Subject svn commit: r1061811 - in /couchdb/branches/1.1.x: share/www/script/test/changes.js src/couchdb/couch_changes.erl
Date Fri, 21 Jan 2011 14:05:08 GMT
Author: fdmanana
Date: Fri Jan 21 14:05:07 2011
New Revision: 1061811

URL: http://svn.apache.org/viewvc?rev=1061811&view=rev
Log:
Merged revision 1061809 from trunk

Fix strange result when passing a filter and a limit of 1 to /db/_changes

Fixes COUCHDB-1037


Modified:
    couchdb/branches/1.1.x/share/www/script/test/changes.js
    couchdb/branches/1.1.x/src/couchdb/couch_changes.erl

Modified: couchdb/branches/1.1.x/share/www/script/test/changes.js
URL: http://svn.apache.org/viewvc/couchdb/branches/1.1.x/share/www/script/test/changes.js?rev=1061811&r1=1061810&r2=1061811&view=diff
==============================================================================
--- couchdb/branches/1.1.x/share/www/script/test/changes.js (original)
+++ couchdb/branches/1.1.x/share/www/script/test/changes.js Fri Jan 21 14:05:07 2011
@@ -461,5 +461,49 @@ couchTests.changes = function(debug) {
     
   });
 
+  // COUCHDB-1037 - empty result for ?limit=1&filter=foo/bar in some cases
+  T(db.deleteDb());
+  T(db.createDb());
+
+  ddoc = {
+    _id: "_design/testdocs",
+    filters: {
+      testdocsonly: (function(doc, req) {
+        return (typeof doc.integer === "number");
+      }).toString()
+    }
+  };
+  T(db.save(ddoc));
+
+  ddoc = {
+    _id: "_design/foobar",
+    foo: "bar"
+  };
+  T(db.save(ddoc));
+
+  db.bulkSave(makeDocs(0, 5));
+
+  req = CouchDB.request("GET", "/" + db.name + "/_changes");
+  resp = JSON.parse(req.responseText);
+  TEquals(7, resp.last_seq);
+  TEquals(7, resp.results.length);
+
+  req = CouchDB.request(
+    "GET", "/"+ db.name + "/_changes?limit=1&filter=testdocs/testdocsonly");
+  resp = JSON.parse(req.responseText);
+  TEquals(3, resp.last_seq);
+  TEquals(1, resp.results.length);
+  TEquals("0", resp.results[0].id);
+
+  req = CouchDB.request(
+    "GET", "/" + db.name + "/_changes?limit=2&filter=testdocs/testdocsonly");
+  resp = JSON.parse(req.responseText);
+  TEquals(4, resp.last_seq);
+  TEquals(2, resp.results.length);
+  TEquals("0", resp.results[0].id);
+  TEquals("1", resp.results[1].id);
+
+  // cleanup
+  db.deleteDb();
 };
 

Modified: couchdb/branches/1.1.x/src/couchdb/couch_changes.erl
URL: http://svn.apache.org/viewvc/couchdb/branches/1.1.x/src/couchdb/couch_changes.erl?rev=1061811&r1=1061810&r2=1061811&view=diff
==============================================================================
--- couchdb/branches/1.1.x/src/couchdb/couch_changes.erl (original)
+++ couchdb/branches/1.1.x/src/couchdb/couch_changes.erl Fri Jan 21 14:05:07 2011
@@ -285,7 +285,7 @@ changes_enumerator(DocInfo, {Db, _, Prep
         = DocInfo,
     Results0 = FilterFun(DocInfo),
     Results = [Result || Result <- Results0, Result /= null],
-    Go = if Limit =< 1 -> stop; true -> ok end,
+    Go = if (Limit =< 1) andalso Results =/= [] -> stop; true -> ok end,
     case Results of
     [] ->
         {Go, {Db, Seq, Prepend, FilterFun, Callback, UserAcc, ResponseType,



Mime
View raw message