You are viewing a plain text version of this content. The canonical link for it is here.
Posted to notifications@couchdb.apache.org by GitBox <gi...@apache.org> on 2018/11/29 13:42:16 UTC

[GitHub] janl commented on a change in pull request #1778: Cache query servers in ets table

janl commented on a change in pull request #1778: Cache query servers in ets table
URL: https://github.com/apache/couchdb/pull/1778#discussion_r237489954
 
 

 ##########
 File path: src/couch/src/couch_proc_manager.erl
 ##########
 @@ -372,23 +382,36 @@ new_proc(Client) ->
     end,
     exit(Resp).
 
-get_env_for_spec(Spec, Target) ->
-    % loop over os:getenv(), match SPEC_TARGET
-    lists:filtermap(fun(VarName) ->
-        SpecStr = Spec ++ Target,
-        case string:tokens(VarName, "=") of
-            [SpecStr, Cmd] -> {true, Cmd};
-            _Else -> false
+split_string_if_longer(String, Pos) ->
+    case length(String) > Pos of
+        true -> lists:split(Pos, String);
+        false -> false
+    end.
+
+split_by_char(String, Char) ->
+    %% 17.5 doesn't have string:split
+    %% the function doesn't handle errors
+    %% it is designed to be used only in specific context
+    Pos = string:chr(String, Char),
+    {Key, [_Eq | Value]} = lists:split(Pos - 1, String),
+    {Key, Value}.
+
+get_servers_from_env(Spec) ->
+    SpecLen = length(Spec),
+    % loop over os:getenv(), match SPEC_
+    lists:filtermap(fun(EnvStr) ->
+        case split_string_if_longer(EnvStr, SpecLen) of
+            {Spec, Rest} ->
+                {true, split_by_char(Rest, $=)};
+            _ ->
+                false
         end
     end, os:getenv()).
 
 get_query_server(LangStr) ->
-    % look for COUCH_QUERY_SERVER_LANGSTR in env
-    % if exists, return value, else undefined
-    UpperLangString = string:to_upper(LangStr),
-    case get_env_for_spec("COUCHDB_QUERY_SERVER_", UpperLangString) of
-        [] -> undefined;
-        [Command] -> Command
+    case ets:lookup(?SERVERS, string:to_upper(LangStr)) of
 
 Review comment:
   doubtful it’s a performance issue, but we could do `to_lower()` when populating the ets table so we can avoid `to_upper()` here on each call. not blocking a merge, just leaving this here.

----------------------------------------------------------------
This is an automated message from the Apache Git Service.
To respond to the message, please log on GitHub and use the
URL above to go to the specific comment.
 
For queries about this service, please contact Infrastructure at:
users@infra.apache.org


With regards,
Apache Git Services