diff options
-rw-r--r-- | share/www/script/couch_tests.js | 4 | ||||
-rw-r--r-- | src/couchdb/couch_btree.erl | 3 | ||||
-rw-r--r-- | src/couchdb/couch_httpd_view.erl | 3 |
3 files changed, 8 insertions, 2 deletions
diff --git a/share/www/script/couch_tests.js b/share/www/script/couch_tests.js index 8876cab8..e436ba00 100644 --- a/share/www/script/couch_tests.js +++ b/share/www/script/couch_tests.js @@ -72,6 +72,10 @@ var tests = { // 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 diff --git a/src/couchdb/couch_btree.erl b/src/couchdb/couch_btree.erl index 30575090..29e82911 100644 --- a/src/couchdb/couch_btree.erl +++ b/src/couchdb/couch_btree.erl @@ -637,7 +637,8 @@ stream_kv_node(Bt, Reds, KVs, StartKey, Dir, Fun, Acc) -> fun({Key, _}) -> less(Bt, StartKey, Key) end end, {LTKVs, GTEKVs} = lists:splitwith(DropFun, KVs), - stream_kv_node2(Bt, Reds, LTKVs, GTEKVs, Dir, Fun, Acc). + AssembleLTKVs = [assemble(Bt,K,V) || {K,V} <- LTKVs], + stream_kv_node2(Bt, Reds, AssembleLTKVs, GTEKVs, Dir, Fun, Acc). stream_kv_node2(_Bt, _Reds, _PrevKVs, [], _Dir, _Fun, Acc) -> {ok, Acc}; diff --git a/src/couchdb/couch_httpd_view.erl b/src/couchdb/couch_httpd_view.erl index d281b82b..f01427a9 100644 --- a/src/couchdb/couch_httpd_view.erl +++ b/src/couchdb/couch_httpd_view.erl @@ -370,7 +370,6 @@ make_view_fold_fun(Req, QueryArgs, Db, TotalViewCount, ReduceCountFun) -> fun({{Key, DocId}, Value}, OffsetReds, {AccCount, AccSkip, Resp, AccRevRows}) -> - Offset = ReduceCountFun(OffsetReds), % I think we only need this call once per view PassedEnd = PassedEndFun(Key, DocId), case {PassedEnd, AccCount, AccSkip, Resp} of {true, _, _, _} -> @@ -383,6 +382,8 @@ make_view_fold_fun(Req, QueryArgs, Db, TotalViewCount, ReduceCountFun) -> {ok, {AccCount, AccSkip - 1, Resp, AccRevRows}}; {_, _, _, undefined} -> {ok, Resp2} = start_json_response(Req, 200), + io:format("OffsetReds:~p~n", [OffsetReds]), + Offset = ReduceCountFun(OffsetReds), JsonBegin = io_lib:format("{\"total_rows\":~w,\"offset\":~w,\"rows\":[\r\n", [TotalViewCount, Offset]), JsonObj = view_row_obj(Db, {{Key, DocId}, Value}, IncludeDocs), |