Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

support "end_key" and "end_docid" in query_view/5 #6

Open
wants to merge 4 commits into
base: master
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
18 changes: 13 additions & 5 deletions hovercraft.erl
Original file line number Diff line number Diff line change
Expand Up @@ -221,7 +221,9 @@ query_view(DbName, DesignName, ViewName, ViewFoldFun, #view_query_args{
direction = Dir,
group_level = GroupLevel,
start_key = StartKey,
start_docid = StartDocId
start_docid = StartDocId,
end_key = EndKey,
end_docid = EndDocId
}=QueryArgs) ->
{ok, Db} = open_db(DbName),
% get view reference
Expand All @@ -230,6 +232,9 @@ query_view(DbName, DesignName, ViewName, ViewFoldFun, #view_query_args{
{ok, View, _Group} ->
{ok, RowCount} = couch_view:get_row_count(View),
Start = {StartKey, StartDocId},
%If EndKey is defined, couchdb expects a tuple {EndKey, EndDocId} to "make_key_in_end_range".
%If EndKey is undefined, couchdb expects atom undefined.
End = case EndKey == undefined of true -> undefined; false -> {EndKey, EndDocId} end,
UpdateSeq = couch_db:get_update_seq(Db),
FoldlFun = couch_httpd_view:make_view_fold_fun(nil,
QueryArgs, <<"">>, Db, UpdateSeq, RowCount,
Expand All @@ -239,10 +244,13 @@ query_view(DbName, DesignName, ViewName, ViewFoldFun, #view_query_args{
send_row = make_map_row_fold_fun(ViewFoldFun)
}),
FoldAccInit = {Limit, SkipCount, undefined, []},
{ok, _, {_Lim, _, _, {Offset, ViewFoldAcc}}} =
couch_view:fold(View, FoldlFun, FoldAccInit,
[{dir, Dir}, {start_key, Start}]),
{ok, {RowCount, Offset, ViewFoldAcc}};
case couch_view:fold(View, FoldlFun, FoldAccInit, [{dir, Dir}, {start_key, Start}, {end_key, End}]) of
{ok, _, {_Lim, _, _, {Offset, ViewFoldAcc}}} ->
{ok, {RowCount, Offset, ViewFoldAcc}};
{ok, _, FoldAccInit} ->
%direction fwd and end_key lower than start_key or vice versa?
{ok, {RowCount, RowCount, []}}
end;
{not_found, Reason} ->
case couch_view:get_reduce_view(Db, DesignId, ViewName, Stale) of
{ok, View, _Group} ->
Expand Down