Return-Path: Delivered-To: apmail-incubator-couchdb-commits-archive@locus.apache.org Received: (qmail 18416 invoked from network); 14 Nov 2008 03:47:48 -0000 Received: from hermes.apache.org (HELO mail.apache.org) (140.211.11.2) by minotaur.apache.org with SMTP; 14 Nov 2008 03:47:48 -0000 Received: (qmail 6375 invoked by uid 500); 14 Nov 2008 03:47:56 -0000 Delivered-To: apmail-incubator-couchdb-commits-archive@incubator.apache.org Received: (qmail 6329 invoked by uid 500); 14 Nov 2008 03:47:55 -0000 Mailing-List: contact couchdb-commits-help@incubator.apache.org; run by ezmlm Precedence: bulk List-Help: List-Unsubscribe: List-Post: List-Id: Reply-To: couchdb-dev@incubator.apache.org Delivered-To: mailing list couchdb-commits@incubator.apache.org Received: (qmail 6320 invoked by uid 99); 14 Nov 2008 03:47:55 -0000 Received: from athena.apache.org (HELO athena.apache.org) (140.211.11.136) by apache.org (qpsmtpd/0.29) with ESMTP; Thu, 13 Nov 2008 19:47:55 -0800 X-ASF-Spam-Status: No, hits=-2000.0 required=10.0 tests=ALL_TRUSTED X-Spam-Check-By: apache.org Received: from [140.211.11.4] (HELO eris.apache.org) (140.211.11.4) by apache.org (qpsmtpd/0.29) with ESMTP; Fri, 14 Nov 2008 03:46:43 +0000 Received: by eris.apache.org (Postfix, from userid 65534) id 6FAB8238898E; Thu, 13 Nov 2008 19:47:27 -0800 (PST) Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit Subject: 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 Date: Fri, 14 Nov 2008 03:47:25 -0000 To: couchdb-commits@incubator.apache.org From: jchris@apache.org X-Mailer: svnmailer-1.0.8 Message-Id: <20081114034727.6FAB8238898E@eris.apache.org> X-Virus-Checked: Checked by ClamAV on apache.org 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 * William Beh + * Antony Blakey * Yoan Blanc * Benoit Chesneau * Paul Joseph Davis 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; _ ->