diff --git a/include/couch_mrview.hrl b/include/couch_mrview.hrl index bfd20ad..cacc984 100644 --- a/include/couch_mrview.hrl +++ b/include/couch_mrview.hrl @@ -10,6 +10,8 @@ % License for the specific language governing permissions and limitations under % the License. +-define(DEFAULT_LIMIT, 16#10000000). + -record(mrst, { sig=nil, fd=nil, @@ -73,7 +75,7 @@ keys, direction = fwd, - limit = 16#10000000, + limit = ?DEFAULT_LIMIT, skip = 0, group_level = 0, group = undefined, diff --git a/src/couch_mrview_http.erl b/src/couch_mrview_http.erl index b554e36..a39d08f 100644 --- a/src/couch_mrview_http.erl +++ b/src/couch_mrview_http.erl @@ -469,10 +469,16 @@ parse_params(Props, Keys, #mrargs{}=Args0, Options) -> IsDecoded = lists:member(decoded, Options), % group_level set to undefined to detect if explicitly set by user Args1 = Args0#mrargs{keys=Keys, group=undefined, group_level=undefined}, - lists:foldl(fun({K, V}, Acc) -> + Args2 = lists:foldl(fun({K, V}, Acc) -> parse_param(K, V, Acc, IsDecoded) - end, Args1, Props). - + end, Args1, Props), + Limit = Args2#mrargs.limit, + case config:get_integer("couch_db", " default_query_limit", -1) of + ConfigDefault0 when ConfigDefault0 < 1 -> + Args2; + ConfigDefault1 -> + Args2#mrargs{limit=min(Limit, ConfigDefault1)} + end. parse_param(Key, Val, Args, IsDecoded) when is_binary(Key) -> parse_param(binary_to_list(Key), Val, Args, IsDecoded); diff --git a/test/couch_mrview_all_docs_tests.erl b/test/couch_mrview_all_docs_tests.erl index 5e35279..dc9bb45 100644 --- a/test/couch_mrview_all_docs_tests.erl +++ b/test/couch_mrview_all_docs_tests.erl @@ -107,6 +107,21 @@ should_query_with_limit_and_skip(Db) -> ]}, ?_assertEqual(Expect, Result). +should_query_with_config_limit_and_skip(Db) -> + ok = config:set("couch_db", "max_query_limit", 3), + Result = run_query(Db, [ + {start_key, <<"2">>}, + {limit, 6}, + {skip, 3} + ]), + Expect = {ok, [ + {meta, [{total, 11}, {offset, 5}]}, + mk_row(<<"5">>, <<"1-aaac5d460fd40f9286e57b9bf12e23d2">>), + mk_row(<<"6">>, <<"1-aca21c2e7bc5f8951424fcfc5d1209d8">>), + mk_row(<<"7">>, <<"1-4374aeec17590d82f16e70f318116ad9">>) + ]}, + ?_assertEqual(Expect, Result). + should_query_with_include_docs(Db) -> Result = run_query(Db, [ {start_key, <<"8">>}, diff --git a/test/couch_mrview_map_views_tests.erl b/test/couch_mrview_map_views_tests.erl index 3a19928..1c44de4 100644 --- a/test/couch_mrview_map_views_tests.erl +++ b/test/couch_mrview_map_views_tests.erl @@ -94,6 +94,15 @@ should_map_with_limit_and_skip(Db) -> ]}, ?_assertEqual(Expect, Result). +should_map_with_config_limit(Db) -> + ok = config:set("couch_db", "max_query_limit", 1), + Result = run_query(Db, []), + Expect = {ok, [ + {meta, [{total, 1}, {offset, 0}]}, + {row, [{id, <<"1">>}, {key, 1}, {value, 1}]} + ]}, + ?_assertEqual(Expect, Result). + should_map_with_include_docs(Db) -> Result = run_query(Db, [ {start_key, 8},