Skip to content

Commit

Permalink
fix: replace maps:foreach with lists:foreach
Browse files Browse the repository at this point in the history
  • Loading branch information
zmstone committed Apr 23, 2022
1 parent d854edf commit 3514ac6
Show file tree
Hide file tree
Showing 4 changed files with 19 additions and 20 deletions.
12 changes: 6 additions & 6 deletions apps/emqx/src/emqx_config.erl
Expand Up @@ -249,8 +249,8 @@ erase(RootName) ->
-spec put(emqx_map_lib:config_key_path(), term()) -> ok.
put(KeyPath, Config) ->
Putter = fun(Path, Map, Value) ->
emqx_map_lib:deep_put(Path, Map, Value)
end,
emqx_map_lib:deep_put(Path, Map, Value)
end,
do_put(?CONF, safe, Putter, KeyPath, Config).

-spec force_put(emqx_map_lib:config_key_path(), term()) -> ok.
Expand All @@ -260,8 +260,8 @@ force_put(KeyPath, Config) ->
-spec force_put(emqx_map_lib:config_key_path(), term(), safe | unsafe) -> ok.
force_put(KeyPath, Config, Safety) ->
Putter = fun(Path, Map, Value) ->
emqx_map_lib:deep_force_put(Path, Map, Value)
end,
emqx_map_lib:deep_force_put(Path, Map, Value)
end,
do_put(?CONF, Safety, Putter, KeyPath, Config).

-spec get_default_value(emqx_map_lib:config_key_path()) -> {ok, term()} | {error, term()}.
Expand Down Expand Up @@ -302,8 +302,8 @@ put_raw(Config) ->
-spec put_raw(emqx_map_lib:config_key_path(), term()) -> ok.
put_raw(KeyPath, Config) ->
Putter = fun(Path, Map, Value) ->
emqx_map_lib:deep_force_put(Path, Map, Value)
end,
emqx_map_lib:deep_force_put(Path, Map, Value)
end,
do_put(?RAW_CONF, safe, Putter, KeyPath, Config).

%%============================================================================
Expand Down
5 changes: 1 addition & 4 deletions apps/emqx/src/emqx_map_lib.erl
Expand Up @@ -81,18 +81,15 @@ deep_force_put([Key | KeyPath] = FullPath, Map, Data) ->
case Map of
#{Key := InnerValue} ->
Map#{Key => deep_force_put(KeyPath, InnerValue, Data)};

#{} ->
maps:put(Key, path_to_map(KeyPath, Data), Map);

_ ->
path_to_map(FullPath, Data)
end.

-spec path_to_map(config_key_path(), term()) -> map().
path_to_map([], Data) -> Data;
path_to_map([Key | Tail], Data) ->
#{Key => path_to_map(Tail, Data)}.
path_to_map([Key | Tail], Data) -> #{Key => path_to_map(Tail, Data)}.

-spec deep_remove(config_key_path(), map()) -> map().
deep_remove([], Map) ->
Expand Down
16 changes: 9 additions & 7 deletions apps/emqx/test/emqx_shared_sub_SUITE.erl
Expand Up @@ -454,24 +454,26 @@ ensure_config(Strategy, AckEnabled) ->
ok.

ensure_group_config(Group2Strategy) ->
maps:foreach(
fun(Group, Strategy) ->
emqx_config:force_put([broker, shared_subscription_group, Group, strategy], Strategy, unsafe)
lists:foreach(
fun({Group, Strategy}) ->
emqx_config:force_put(
[broker, shared_subscription_group, Group, strategy], Strategy, unsafe
)
end,
Group2Strategy
maps:to_list(Group2Strategy)
).

ensure_group_config(Node, Group2Strategy) ->
maps:foreach(
fun(Group, Strategy) ->
lists:foreach(
fun({Group, Strategy}) ->
rpc:call(
Node,
emqx_config,
force_put,
[[broker, shared_subscription_group, Group, strategy], Strategy, unsafe]
)
end,
Group2Strategy
maps:to_list(Group2Strategy)
).

subscribed(Group, Topic, Pid) ->
Expand Down
6 changes: 3 additions & 3 deletions apps/emqx_machine/src/emqx_machine.erl
Expand Up @@ -92,10 +92,10 @@ update_vips() ->

configure_shard_transports() ->
ShardTransports = application:get_env(emqx_machine, custom_shard_transports, #{}),
maps:foreach(
fun(ShardBin, Transport) ->
lists:foreach(
fun({ShardBin, Transport}) ->
ShardName = binary_to_existing_atom(ShardBin),
mria_config:set_shard_transport(ShardName, Transport)
end,
ShardTransports
maps:to_list(ShardTransports)
).

0 comments on commit 3514ac6

Please sign in to comment.