rnewson commented on code in PR #4494:
URL: https://github.com/apache/couchdb/pull/4494#discussion_r1156139741


##########
src/couch_mrview/src/couch_mrview_util.erl:
##########
@@ -581,13 +581,12 @@ validate_args(Args) ->
             ok;
         {[], _, _} ->
             ok;
+        {[Key], StartKey, EndKey} when Key =:= StartKey andalso Key =:= EndKey 
->

Review Comment:
   `{[Key], Key, Key}` is a less verbose equivalent. Not essential. 



##########
src/couch_mrview/src/couch_mrview_http.erl:
##########
@@ -530,9 +547,15 @@ parse_param(Key, Val, Args, IsDecoded) ->
             JsonKey = ?JSON_DECODE(Val),
             Args#mrargs{start_key = JsonKey, end_key = JsonKey};
         "keys" when IsDecoded ->
-            Args#mrargs{keys = Val};
+            case Val of
+                [SingleKeys] -> Args#mrargs{start_key = SingleKeys, end_key = 
SingleKeys};
+                _ -> Args#mrargs{keys = Val}
+            end;
         "keys" ->
-            Args#mrargs{keys = ?JSON_DECODE(Val)};
+            case ?JSON_DECODE(Val) of
+                [SingleKeys] -> Args#mrargs{start_key = SingleKeys, end_key = 
SingleKeys};

Review Comment:
   `Key` here also for the same reason.



##########
src/couch_mrview/src/couch_mrview_http.erl:
##########
@@ -530,9 +547,15 @@ parse_param(Key, Val, Args, IsDecoded) ->
             JsonKey = ?JSON_DECODE(Val),
             Args#mrargs{start_key = JsonKey, end_key = JsonKey};
         "keys" when IsDecoded ->
-            Args#mrargs{keys = Val};
+            case Val of
+                [SingleKeys] -> Args#mrargs{start_key = SingleKeys, end_key = 
SingleKeys};

Review Comment:
   `SingleKey` or simply `Key` reads better; it is (by definition) not plural.



##########
src/couch_mrview/src/couch_mrview_http.erl:
##########
@@ -513,8 +518,20 @@ parse_body_and_query(Req, Keys) ->
 
 parse_body_and_query(Req, {Props}, Keys) ->
     Args = #mrargs{keys = Keys, group = undefined, group_level = undefined},
-    BodyArgs = parse_params(Props, Keys, Args, [decoded]),
-    parse_params(chttpd:qs(Req), Keys, BodyArgs, [keep_group_level]).
+    BodyArgs0 = parse_params(Props, Keys, Args, [decoded]),
+    BodyArgs1 = treat_single_keys_as_key(Req, BodyArgs0),
+    parse_params(chttpd:qs(Req), Keys, BodyArgs1, [keep_group_level]).
+
+treat_single_keys_as_key(#httpd{path_parts = Path}, #mrargs{keys = Keys} = 
BodyArgs) ->
+    case lists:member(<<"_view">>, Path) of

Review Comment:
   `_view` only has a special meaning in certain path parts, so this isn't 
quite right. I think we'll need a caluse that matches `_view` in the correct 
place and then another clause that doesn't look at path_parts and just returns 
`BodyArgs` (for the _all_docs case, right?).



-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: [email protected]

For queries about this service, please contact Infrastructure at:
[email protected]

Reply via email to