couchdb-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From kocol...@apache.org
Subject svn commit: r1161965 - in /couchdb/trunk: share/www/script/couch.js share/www/script/test/basics.js src/couchdb/couch_key_tree.erl
Date Fri, 26 Aug 2011 02:36:21 GMT
Author: kocolosk
Date: Fri Aug 26 02:36:21 2011
New Revision: 1161965

URL: http://svn.apache.org/viewvc?rev=1161965&view=rev
Log:
Fix latest=true parameter for multi-revision reads

The latest=true flag is an optimization used by the replicator to
automatically receive a descendant of a requested revision instead of
the revision itself.  This patch fixes a couple of bugs in the core
database layer, but the net effect of those bugs was that setting
latest=true was a no-op: the server would always respond with the
revisions requested by the client, not the leaf revisions accessible
from the requested revisions.

Closes COUCHDB-954

Modified:
    couchdb/trunk/share/www/script/couch.js
    couchdb/trunk/share/www/script/test/basics.js
    couchdb/trunk/src/couchdb/couch_key_tree.erl

Modified: couchdb/trunk/share/www/script/couch.js
URL: http://svn.apache.org/viewvc/couchdb/trunk/share/www/script/couch.js?rev=1161965&r1=1161964&r2=1161965&view=diff
==============================================================================
--- couchdb/trunk/share/www/script/couch.js [utf-8] (original)
+++ couchdb/trunk/share/www/script/couch.js [utf-8] Fri Aug 26 02:36:21 2011
@@ -272,7 +272,7 @@ function CouchDB(name, httpHeaders) {
       for (var name in options) {
         if (!options.hasOwnProperty(name)) { continue; };
         var value = options[name];
-        if (name == "key" || name == "keys" || name == "startkey" || name == "endkey") {
+        if (name == "key" || name == "keys" || name == "startkey" || name == "endkey" ||
(name == "open_revs" && value !== "all")) {
           value = toJSON(value);
         }
         buf.push(encodeURIComponent(name) + "=" + encodeURIComponent(value));

Modified: couchdb/trunk/share/www/script/test/basics.js
URL: http://svn.apache.org/viewvc/couchdb/trunk/share/www/script/test/basics.js?rev=1161965&r1=1161964&r2=1161965&view=diff
==============================================================================
--- couchdb/trunk/share/www/script/test/basics.js (original)
+++ couchdb/trunk/share/www/script/test/basics.js Fri Aug 26 02:36:21 2011
@@ -81,6 +81,28 @@ couchTests.basics = function(debug) {
   // Check the database doc count
   T(db.info().doc_count == 4);
 
+  // COUCHDB-954
+  var oldRev = db.save({_id:"COUCHDB-954", a:1}).rev;
+  var newRev = db.save({_id:"COUCHDB-954", _rev:oldRev}).rev;
+
+  // test behavior of open_revs with explicit revision list
+  var result = db.open("COUCHDB-954", {open_revs:[oldRev,newRev]});
+  T(result.length == 2, "should get two revisions back");
+  T(result[0].ok);
+  T(result[1].ok);
+
+  // latest=true suppresses non-leaf revisions
+  var result = db.open("COUCHDB-954", {open_revs:[oldRev,newRev], latest:true});
+  T(result.length == 1, "should only get the child revision with latest=true");
+  T(result[0].ok._rev == newRev, "should get the child and not the parent");
+
+  // latest=true returns a child when you ask for a parent
+  var result = db.open("COUCHDB-954", {open_revs:[oldRev], latest:true});
+  T(result[0].ok._rev == newRev, "should get child when we requested parent");
+
+  // clean up after ourselves
+  db.save({_id:"COUCHDB-954", _rev:newRev, _deleted:true});
+
   // Test a simple map functions
 
   // create a map function that selects all documents whose "a" member

Modified: couchdb/trunk/src/couchdb/couch_key_tree.erl
URL: http://svn.apache.org/viewvc/couchdb/trunk/src/couchdb/couch_key_tree.erl?rev=1161965&r1=1161964&r2=1161965&view=diff
==============================================================================
--- couchdb/trunk/src/couchdb/couch_key_tree.erl (original)
+++ couchdb/trunk/src/couchdb/couch_key_tree.erl Fri Aug 26 02:36:21 2011
@@ -235,9 +235,10 @@ get_key_leafs_simple(Pos, [{Key, _Value,
         {LeafsFound ++ RestLeafsFound, KeysRemaining};
     KeysToGet2 ->
         LeafsFound = get_all_leafs_simple(Pos, [Tree], KeyPathAcc),
-        LeafKeysFound = [LeafKeyFound || {LeafKeyFound, _} <- LeafsFound],
-        KeysToGet2 = KeysToGet2 -- LeafKeysFound,
-        {RestLeafsFound, KeysRemaining} = get_key_leafs_simple(Pos, RestTree, KeysToGet2,
KeyPathAcc),
+        LeafKeysFound = [{LeafPos, LeafRev} || {_, {LeafPos, [LeafRev|_]}}
+            <- LeafsFound],
+        KeysToGet3 = KeysToGet2 -- LeafKeysFound,
+        {RestLeafsFound, KeysRemaining} = get_key_leafs_simple(Pos, RestTree, KeysToGet3,
KeyPathAcc),
         {LeafsFound ++ RestLeafsFound, KeysRemaining}
     end.
 



Mime
View raw message