couchdb-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From kocol...@apache.org
Subject svn commit: r1161697 - in /couchdb/trunk: share/www/script/test/changes.js src/couchdb/couch_db.erl
Date Thu, 25 Aug 2011 19:02:27 GMT
Author: kocolosk
Date: Thu Aug 25 19:02:27 2011
New Revision: 1161697

URL: http://svn.apache.org/viewvc?rev=1161697&view=rev
Log:
Do not suppress old revisions from _changes

Requests to '_changes?style=all_docs' with a 'since' parameter would
suppress revisions of a document generated before the start of the
feed.  The assumption may have been that those revisions were seen by
the client in a previous request to _changes, but this is not
necessarily true if the client is resuming the feed after a partial
download.

The safe thing to do is to include all leaf revisions for each document
in the feed.

Thanks Bob Dionne for the test code.

Closes COUCHDB-1256

Modified:
    couchdb/trunk/share/www/script/test/changes.js
    couchdb/trunk/src/couchdb/couch_db.erl

Modified: couchdb/trunk/share/www/script/test/changes.js
URL: http://svn.apache.org/viewvc/couchdb/trunk/share/www/script/test/changes.js?rev=1161697&r1=1161696&r2=1161697&view=diff
==============================================================================
--- couchdb/trunk/share/www/script/test/changes.js (original)
+++ couchdb/trunk/share/www/script/test/changes.js Thu Aug 25 19:02:27 2011
@@ -524,6 +524,32 @@ couchTests.changes = function(debug) {
   CouchDB.request("GET", "/" + db.name + "/_changes");
   TEquals(0, CouchDB.requestStats('httpd', 'clients_requesting_changes').current);
 
+  // COUCHDB-1256
+  T(db.deleteDb());
+  T(db.createDb());
+
+  T(db.save({"_id":"foo", "a" : 123}).ok);
+  T(db.save({"_id":"bar", "a" : 456}).ok);
+
+  options = {
+      headers: {"Content-Type": "application/json"},
+      body: JSON.stringify({"_rev":"1-cc609831f0ca66e8cd3d4c1e0d98108a", "a":456})
+  };
+  req = CouchDB.request("PUT", "/" + db.name + "/foo?new_edits=false", options);
+
+  req = CouchDB.request("GET", "/" + db.name + "/_changes?style=all_docs");
+  resp = JSON.parse(req.responseText);
+
+  TEquals(3, resp.last_seq);
+  TEquals(2, resp.results.length);
+
+  req = CouchDB.request("GET", "/" + db.name + "/_changes?style=all_docs&since=2");
+  resp = JSON.parse(req.responseText);
+
+  TEquals(3, resp.last_seq);
+  TEquals(1, resp.results.length);
+  TEquals(2, resp.results[0].changes.length);
+
   // cleanup
   db.deleteDb();
 };

Modified: couchdb/trunk/src/couchdb/couch_db.erl
URL: http://svn.apache.org/viewvc/couchdb/trunk/src/couchdb/couch_db.erl?rev=1161697&r1=1161696&r2=1161697&view=diff
==============================================================================
--- couchdb/trunk/src/couchdb/couch_db.erl (original)
+++ couchdb/trunk/src/couchdb/couch_db.erl Thu Aug 25 19:02:27 2011
@@ -1028,20 +1028,8 @@ enum_docs_reduce_to_count(Reds) ->
 changes_since(Db, Style, StartSeq, Fun, Acc) ->
     changes_since(Db, Style, StartSeq, Fun, [], Acc).
     
-changes_since(Db, Style, StartSeq, Fun, Options, Acc) ->
-    Wrapper = fun(DocInfo, _Offset, Acc2) ->
-            #doc_info{revs=Revs} = DocInfo,
-            DocInfo2 =
-            case Style of
-            main_only ->
-                DocInfo;
-            all_docs ->
-                % remove revs before the seq
-                DocInfo#doc_info{revs=[RevInfo ||
-                    #rev_info{seq=RevSeq}=RevInfo <- Revs, StartSeq < RevSeq]}
-            end,
-            Fun(DocInfo2, Acc2)
-        end,
+changes_since(Db, _Style, StartSeq, Fun, Options, Acc) ->
+    Wrapper = fun(DocInfo, _Offset, Acc2) -> Fun(DocInfo, Acc2) end,
     {ok, _LastReduction, AccOut} = couch_btree:fold(by_seq_btree(Db),
         Wrapper, Acc, [{start_key, StartSeq + 1}] ++ Options),
     {ok, AccOut}.



Mime
View raw message