diff options
author | John Christopher Anderson <jchris@apache.org> | 2008-10-05 05:54:10 +0000 |
---|---|---|
committer | John Christopher Anderson <jchris@apache.org> | 2008-10-05 05:54:10 +0000 |
commit | 023179170f616f574fb65db8c5e6bf65cfc5bebf (patch) | |
tree | 324b283a65daca5998560bee11f8317bd36aa835 /src/couchdb | |
parent | 53b9d1275f3e0d25cbf637eee651e94382dd6a01 (diff) |
refactor couch_httpd_view to use output_map_view
git-svn-id: https://svn.apache.org/repos/asf/incubator/couchdb/trunk@701749 13f79535-47bb-0310-9956-ffa450edef68
Diffstat (limited to 'src/couchdb')
-rw-r--r-- | src/couchdb/couch_httpd_view.erl | 57 |
1 files changed, 19 insertions, 38 deletions
diff --git a/src/couchdb/couch_httpd_view.erl b/src/couchdb/couch_httpd_view.erl index e634e8e2..c513e750 100644 --- a/src/couchdb/couch_httpd_view.erl +++ b/src/couchdb/couch_httpd_view.erl @@ -24,24 +24,13 @@ handle_view_req(#httpd{method='GET',path_parts=[_,_, Id, ViewName]}=Req, Db) -> #view_query_args{ - start_key = StartKey, - count = Count, - skip = SkipCount, - direction = Dir, - start_docid = StartDocId, reduce = Reduce } = QueryArgs = parse_view_query(Req), case couch_view:get_map_view({couch_db:name(Db), <<"_design/", Id/binary>>, ViewName}) of {ok, View} -> - {ok, RowCount} = couch_view:get_row_count(View), - Start = {StartKey, StartDocId}, - FoldlFun = make_view_fold_fun(Req, QueryArgs, RowCount, - fun couch_view:reduce_to_count/1), - FoldAccInit = {Count, SkipCount, undefined, []}, - FoldResult = couch_view:fold(View, Start, Dir, FoldlFun, FoldAccInit), - finish_view_fold(Req, RowCount, FoldResult); + output_map_view(Req, View, QueryArgs); {not_found, Reason} -> case couch_view:get_reduce_view({couch_db:name(Db), <<"_design/", Id/binary>>, ViewName}) of @@ -49,13 +38,7 @@ handle_view_req(#httpd{method='GET',path_parts=[_,_, Id, ViewName]}=Req, Db) -> case Reduce of false -> {reduce, _N, _Lang, MapView} = View, - {ok, RowCount} = couch_view:get_row_count(MapView), - Start = {StartKey, StartDocId}, - FoldlFun = make_view_fold_fun(Req, QueryArgs, RowCount, - fun couch_view:reduce_to_count/1), - FoldAccInit = {Count, SkipCount, undefined, []}, - FoldResult = couch_view:fold(MapView, Start, Dir, FoldlFun, FoldAccInit), - finish_view_fold(Req, RowCount, FoldResult); + output_map_view(Req, MapView, QueryArgs); _ -> output_reduce_view(Req, View) end; @@ -68,13 +51,7 @@ handle_view_req(Req, _Db) -> send_method_not_allowed(Req, "GET,HEAD"). handle_temp_view_req(#httpd{method='POST'}=Req, Db) -> - #view_query_args{ - start_key = StartKey, - count = Count, - skip = SkipCount, - direction = Dir, - start_docid = StartDocId - } = QueryArgs = parse_view_query(Req), + QueryArgs = parse_view_query(Req), case couch_httpd:primary_header_value(Req, "content-type") of undefined -> ok; @@ -87,18 +64,7 @@ handle_temp_view_req(#httpd{method='POST'}=Req, Db) -> case proplists:get_value(<<"reduce">>, Props, null) of null -> {ok, View} = couch_view:get_map_view({temp, couch_db:name(Db), Language, MapSrc}), - Start = {StartKey, StartDocId}, - - {ok, TotalRows} = couch_view:get_row_count(View), - - FoldlFun = make_view_fold_fun(Req, QueryArgs, TotalRows, - fun couch_view:reduce_to_count/1), - FoldAccInit = {Count, SkipCount, undefined, []}, - FoldResult = couch_view:fold(View, Start, Dir, fun(A, B, C) -> - FoldlFun(A, B, C) - end, FoldAccInit), - finish_view_fold(Req, TotalRows, FoldResult); - + output_map_view(Req, View, QueryArgs); RedSrc -> {ok, View} = couch_view:get_reduce_view( {temp, couch_db:name(Db), Language, MapSrc, RedSrc}), @@ -108,6 +74,21 @@ handle_temp_view_req(#httpd{method='POST'}=Req, Db) -> handle_temp_view_req(Req, _Db) -> send_method_not_allowed(Req, "POST"). +output_map_view(Req, View, QueryArgs) -> + #view_query_args{ + count = Count, + direction = Dir, + skip = SkipCount, + start_key = StartKey, + start_docid = StartDocId + } = QueryArgs, + {ok, RowCount} = couch_view:get_row_count(View), + Start = {StartKey, StartDocId}, + FoldlFun = make_view_fold_fun(Req, QueryArgs, RowCount, + fun couch_view:reduce_to_count/1), + FoldAccInit = {Count, SkipCount, undefined, []}, + FoldResult = couch_view:fold(View, Start, Dir, FoldlFun, FoldAccInit), + finish_view_fold(Req, RowCount, FoldResult). output_reduce_view(Req, View) -> #view_query_args{ |