Author: fdmanana Date: Fri Jan 21 14:04:38 2011 New Revision: 1061810 URL: http://svn.apache.org/viewvc?rev=1061810&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.0.x/share/www/script/test/changes.js couchdb/branches/1.0.x/src/couchdb/couch_changes.erl Modified: couchdb/branches/1.0.x/share/www/script/test/changes.js URL: http://svn.apache.org/viewvc/couchdb/branches/1.0.x/share/www/script/test/changes.js?rev=1061810&r1=1061809&r2=1061810&view=diff ============================================================================== --- couchdb/branches/1.0.x/share/www/script/test/changes.js (original) +++ couchdb/branches/1.0.x/share/www/script/test/changes.js Fri Jan 21 14:04:38 2011 @@ -398,5 +398,49 @@ couchTests.changes = function(debug) { T(resp.results[1].id === "doc4"); }); + // 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.0.x/src/couchdb/couch_changes.erl URL: http://svn.apache.org/viewvc/couchdb/branches/1.0.x/src/couchdb/couch_changes.erl?rev=1061810&r1=1061809&r2=1061810&view=diff ============================================================================== --- couchdb/branches/1.0.x/src/couchdb/couch_changes.erl (original) +++ couchdb/branches/1.0.x/src/couchdb/couch_changes.erl Fri Jan 21 14:04:38 2011 @@ -229,7 +229,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, ResponseType, Limit,