diff options
-rw-r--r-- | share/www/script/test/purge.js | 32 | ||||
-rw-r--r-- | src/couchdb/couch_db_updater.erl | 5 |
2 files changed, 35 insertions, 2 deletions
diff --git a/share/www/script/test/purge.js b/share/www/script/test/purge.js index f8f45138..29689137 100644 --- a/share/www/script/test/purge.js +++ b/share/www/script/test/purge.js @@ -110,4 +110,36 @@ couchTests.purge = function(debug) { T(rows[(2*(i-4))+1].key == i+1); } T(db.view("test/single_doc").total_rows == 0); + + // COUCHDB-1065 + var dbA = new CouchDB("test_suite_db_a"); + var dbB = new CouchDB("test_suite_db_b"); + dbA.deleteDb(); + dbA.createDb(); + dbB.deleteDb(); + dbB.createDb(); + var docA = {_id:"test", a:1}; + var docB = {_id:"test", a:2}; + dbA.save(docA); + dbB.save(docB); + CouchDB.replicate(dbA.name, dbB.name); + var xhr = CouchDB.request("POST", "/" + dbB.name + "/_purge", { + body: JSON.stringify({"test":[docA._rev]}) + }); + TEquals(200, xhr.status, "single rev purge after replication succeeds"); + + var xhr = CouchDB.request("GET", "/" + dbB.name + "/test?rev=" + docA._rev); + TEquals(404, xhr.status, "single rev purge removes revision"); + + var xhr = CouchDB.request("POST", "/" + dbB.name + "/_purge", { + body: JSON.stringify({"test":[docB._rev]}) + }); + TEquals(200, xhr.status, "single rev purge after replication succeeds"); + var xhr = CouchDB.request("GET", "/" + dbB.name + "/test?rev=" + docB._rev); + TEquals(404, xhr.status, "single rev purge removes revision"); + + var xhr = CouchDB.request("POST", "/" + dbB.name + "/_purge", { + body: JSON.stringify({"test":[docA._rev, docB._rev]}) + }); + TEquals(200, xhr.status, "all rev purge after replication succeeds"); }; diff --git a/src/couchdb/couch_db_updater.erl b/src/couchdb/couch_db_updater.erl index c14d6bf9..2b317d95 100644 --- a/src/couchdb/couch_db_updater.erl +++ b/src/couchdb/couch_db_updater.erl @@ -118,8 +118,9 @@ handle_call({purge_docs, IdRevs}, _From, Db) -> {DocInfoToUpdate, NewSeq} = lists:mapfoldl( fun(#full_doc_info{rev_tree=Tree}=FullInfo, SeqAcc) -> - Tree2 = couch_key_tree:map_leafs( fun(RevInfo) -> - RevInfo#rev_info{seq=SeqAcc + 1} + Tree2 = couch_key_tree:map_leafs( + fun(_RevId, {IsDeleted, BodyPointer, _UpdateSeq}) -> + {IsDeleted, BodyPointer, SeqAcc + 1} end, Tree), {couch_doc:to_doc_info(FullInfo#full_doc_info{rev_tree=Tree2}), SeqAcc + 1} |