You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@couchdb.apache.org by jc...@apache.org on 2008/11/14 04:47:25 UTC

svn commit: r713914 - in /incubator/couchdb/trunk: THANKS share/www/script/couch.js share/www/script/couch_tests.js src/couchdb/couch_httpd_view.erl

Author: jchris
Date: Thu Nov 13 19:47:21 2008
New Revision: 713914

URL: http://svn.apache.org/viewvc?rev=713914&view=rev
Log:
fix for _all_docs_by_seq with include_docs

Modified:
    incubator/couchdb/trunk/THANKS
    incubator/couchdb/trunk/share/www/script/couch.js
    incubator/couchdb/trunk/share/www/script/couch_tests.js
    incubator/couchdb/trunk/src/couchdb/couch_httpd_view.erl

Modified: incubator/couchdb/trunk/THANKS
URL: http://svn.apache.org/viewvc/incubator/couchdb/trunk/THANKS?rev=713914&r1=713913&r2=713914&view=diff
==============================================================================
--- incubator/couchdb/trunk/THANKS (original)
+++ incubator/couchdb/trunk/THANKS Thu Nov 13 19:47:21 2008
@@ -8,6 +8,7 @@
 
  * Mark Baran <me...@gmail.com>
  * William Beh <wi...@gmail.com>
+ * Antony Blakey <an...@gmail.com>
  * Yoan Blanc <yo...@gmail.com>
  * Benoit Chesneau <bc...@gmail.com>
  * Paul Joseph Davis <pa...@gmail.com>

Modified: incubator/couchdb/trunk/share/www/script/couch.js
URL: http://svn.apache.org/viewvc/incubator/couchdb/trunk/share/www/script/couch.js?rev=713914&r1=713913&r2=713914&view=diff
==============================================================================
--- incubator/couchdb/trunk/share/www/script/couch.js [utf-8] (original)
+++ incubator/couchdb/trunk/share/www/script/couch.js [utf-8] Thu Nov 13 19:47:21 2008
@@ -162,6 +162,20 @@
     return JSON.parse(req.responseText);
   }
 
+  this.allDocsBySeq = function(options,keys) {
+    var req = null;
+    if(!keys) {
+      req = request("GET", this.uri + "_all_docs_by_seq" + encodeOptions(options));      
+    } else {
+      req = request("POST", this.uri + "_all_docs_by_seq" + encodeOptions(options), {
+        headers: {"Content-Type": "application/json"},
+        body: JSON.stringify({keys:keys})
+      });      
+    }
+    maybeThrowError(req);
+    return JSON.parse(req.responseText);
+  }
+
   this.compact = function() {
     var req = request("POST", this.uri + "_compact");
     maybeThrowError(req);

Modified: incubator/couchdb/trunk/share/www/script/couch_tests.js
URL: http://svn.apache.org/viewvc/incubator/couchdb/trunk/share/www/script/couch_tests.js?rev=713914&r1=713913&r2=713914&view=diff
==============================================================================
--- incubator/couchdb/trunk/share/www/script/couch_tests.js [utf-8] (original)
+++ incubator/couchdb/trunk/share/www/script/couch_tests.js [utf-8] Thu Nov 13 19:47:21 2008
@@ -67,24 +67,6 @@
     // Check the database doc count
     T(db.info().doc_count == 4);
 
-    // Check the all docs
-    var results = db.allDocs();
-    var rows = results.rows;
-
-    T(results.total_rows == results.rows.length);
-
-    for(var i=0; i < rows.length; i++) {
-      T(rows[i].id >= "0" && rows[i].id <= "4");
-    }
-    
-    // Check _all_docs with descending=true
-    var desc = db.allDocs({descending:true});
-    T(desc.total_rows == desc.rows.length);
- 
-    // Check _all_docs offset
-    var all = db.allDocs({startkey:"2"});
-    T(all.offset == 2);
-
     // Test a simple map functions
 
     // create a map function that selects all documents whose "a" member
@@ -150,7 +132,80 @@
     // make sure restart works
     T(restartServer().ok);
   },
+  all_docs: function(debug) {
+    var db = new CouchDB("test_suite_db");
+    db.deleteDb();
+    db.createDb();
+    if (debug) debugger;
+    
+    // Create some more documents.
+    // Notice the use of the ok member on the return result.
+    T(db.save({_id:"0",a:1,b:1}).ok);
+    T(db.save({_id:"3",a:4,b:16}).ok);
+    T(db.save({_id:"1",a:2,b:4}).ok);
+    T(db.save({_id:"2",a:3,b:9}).ok);
 
+    // Check the all docs
+    var results = db.allDocs();
+    var rows = results.rows;
+
+    T(results.total_rows == results.rows.length);
+
+    for(var i=0; i < rows.length; i++) {
+      T(rows[i].id >= "0" && rows[i].id <= "4");
+    }
+    
+    // Check _all_docs with descending=true
+    var desc = db.allDocs({descending:true});
+    T(desc.total_rows == desc.rows.length);
+ 
+    // Check _all_docs offset
+    var all = db.allDocs({startkey:"2"});
+    T(all.offset == 2);
+    
+    // check that the docs show up in the seq view in the order they were created
+    var all_seq = db.allDocsBySeq();
+    var ids = ["0","3","1","2"];
+    for (var i=0; i < all_seq.rows.length; i++) {
+      var row = all_seq.rows[i];
+      T(row.id == ids[i]);
+    };
+    
+    // check that deletions also show up right
+    var doc1 = db.open("1");
+    var deleted = db.deleteDoc(doc1);
+    T(deleted.ok);
+    all_seq = db.allDocsBySeq();
+    
+    // the deletion should make doc id 1 have the last seq num
+    T(all_seq.rows.length == 4);
+    T(all_seq.rows[3].id == "1");
+    T(all_seq.rows[3].value.deleted);
+
+    // is this a bug?
+    // T(all_seq.rows.length == all_seq.total_rows);
+    
+    // do an update
+    var doc2 = db.open("3");
+    doc2.updated = "totally";
+    db.save(doc2);
+    all_seq = db.allDocsBySeq();
+    
+    // the update should make doc id 3 have the last seq num
+    T(all_seq.rows.length == 4);
+    T(all_seq.rows[3].id == "3");
+
+    // ok now lets see what happens with include docs
+    all_seq = db.allDocsBySeq({include_docs: true});
+    T(all_seq.rows.length == 4);
+    T(all_seq.rows[3].id == "3");
+    T(all_seq.rows[3].doc.updated == "totally");
+
+    // and on the deleted one, no doc
+    T(all_seq.rows[2].value.deleted);
+    T(!all_seq.rows[2].doc);
+  },
+  
   // Do some edit conflict detection tests
   conflicts: function(debug) {
     var db = new CouchDB("test_suite_db");

Modified: incubator/couchdb/trunk/src/couchdb/couch_httpd_view.erl
URL: http://svn.apache.org/viewvc/incubator/couchdb/trunk/src/couchdb/couch_httpd_view.erl?rev=713914&r1=713913&r2=713914&view=diff
==============================================================================
--- incubator/couchdb/trunk/src/couchdb/couch_httpd_view.erl (original)
+++ incubator/couchdb/trunk/src/couchdb/couch_httpd_view.erl Thu Nov 13 19:47:21 2008
@@ -426,12 +426,13 @@
                 []
             end,
             ?LOG_DEBUG("Include Doc: ~p ~p", [DocId, Rev]),
-            case (catch couch_httpd_db:couch_doc_open(Db, DocId, 
-                Rev, [])) of
-            {{not_found, missing}, _} ->
+            case (catch couch_httpd_db:couch_doc_open(Db, DocId, Rev, [])) of
+              {{not_found, missing}, _} ->
                 {[{id, DocId}, {key, Key}, {value, Value}, {error, missing}]};
-            Doc ->
-                JsonDoc = couch_doc:to_json_obj(Doc, []),
+              {not_found, deleted} ->
+                {[{id, DocId}, {key, Key}, {value, Value}]};
+              Doc ->
+                JsonDoc = couch_doc:to_json_obj(Doc, []), 
                 {[{id, DocId}, {key, Key}, {value, Value}, {doc, JsonDoc}]}
             end;
         _ ->