diff options
-rw-r--r-- | share/www/script/couch_tests.js | 6 | ||||
-rw-r--r-- | src/couchdb/couch_db_updater.erl | 14 |
2 files changed, 17 insertions, 3 deletions
diff --git a/share/www/script/couch_tests.js b/share/www/script/couch_tests.js index 91ee5469..78307062 100644 --- a/share/www/script/couch_tests.js +++ b/share/www/script/couch_tests.js @@ -56,9 +56,15 @@ var tests = { 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); // Test a simple map functions diff --git a/src/couchdb/couch_db_updater.erl b/src/couchdb/couch_db_updater.erl index befbfed2..cc916961 100644 --- a/src/couchdb/couch_db_updater.erl +++ b/src/couchdb/couch_db_updater.erl @@ -147,13 +147,13 @@ btree_by_id_join(Id, {Seq, Deleted, Tree}) -> btree_by_id_reduce(reduce, FullDocInfos) -> - % count the number of deleted documents + % count the number of not deleted documents length([1 || #full_doc_info{deleted=false} <- FullDocInfos]); btree_by_id_reduce(rereduce, Reds) -> lists:sum(Reds). btree_by_seq_reduce(reduce, DocInfos) -> - % count the number of deleted documents + % count the number of documents length(DocInfos); btree_by_seq_reduce(rereduce, Reds) -> lists:sum(Reds). @@ -161,10 +161,18 @@ btree_by_seq_reduce(rereduce, Reds) -> init_db(DbName, Filepath, Fd, Header) -> {ok, SummaryStream} = couch_stream:open(Header#db_header.summary_stream_state, Fd), ok = couch_stream:set_min_buffer(SummaryStream, 10000), + Less = + fun(A,B) when A==B -> false; + (nil, _) -> true; % nil - special key sorts before all + ({}, _) -> false; % {} -> special key sorts after all + (A, B) -> A < B + end, + {ok, IdBtree} = couch_btree:open(Header#db_header.fulldocinfo_by_id_btree_state, Fd, [{split, fun(X) -> btree_by_id_split(X) end}, {join, fun(X,Y) -> btree_by_id_join(X,Y) end}, - {reduce, fun(X,Y) -> btree_by_id_reduce(X,Y) end}]), + {reduce, fun(X,Y) -> btree_by_id_reduce(X,Y) end}, + {less, Less}]), {ok, SeqBtree} = couch_btree:open(Header#db_header.docinfo_by_seq_btree_state, Fd, [{split, fun(X) -> btree_by_seq_split(X) end}, {join, fun(X,Y) -> btree_by_seq_join(X,Y) end}, |