Skip to content

Commit

Permalink
qf-foreach: skip creating lists by using lists:foreach when able (260…
Browse files Browse the repository at this point in the history
  • Loading branch information
fenollp authored and lazedo committed Aug 23, 2016
1 parent 38e59a8 commit b6d8019
Show file tree
Hide file tree
Showing 25 changed files with 75 additions and 106 deletions.
2 changes: 1 addition & 1 deletion applications/acdc/src/acdc_agent_listener.erl
Original file line number Diff line number Diff line change
Expand Up @@ -553,7 +553,7 @@ handle_cast({'member_connect_retry', CallId}, #state{my_id=MyId
lager:debug("need to retry member connect, agent isn't able to take it"),
send_member_connect_retry(Server, CallId, MyId, AgentId),

_ = [acdc_util:unbind_from_call_events(ACallId) || ACallId <- ACallIds],
lists:foreach(fun acdc_util:unbind_from_call_events/1, ACallIds),
acdc_util:unbind_from_call_events(CallId),

kz_util:put_callid(AgentId),
Expand Down
3 changes: 1 addition & 2 deletions applications/acdc/src/acdc_agent_maintenance.erl
Original file line number Diff line number Diff line change
Expand Up @@ -26,8 +26,7 @@ acct_status(AcctId) ->
[] -> lager:info("no agents with account id ~s available", [AcctId]);
As ->
lager:info("Agent Statuses in ~s", [AcctId]),
_ = [acdc_agent_sup:status(Sup) || Sup <- As],
'ok'
lists:foreach(fun acdc_agent_sup:status/1, As)
end.

agent_status(AcctId, AgentId) when (not is_binary(AcctId))
Expand Down
7 changes: 2 additions & 5 deletions applications/acdc/src/acdc_agents_sup.erl
Original file line number Diff line number Diff line change
Expand Up @@ -47,16 +47,13 @@ start_link() ->
status() ->
lager:info("ACDc Agents Status"),
Ws = workers(),
_ = kz_util:spawn(fun() -> [acdc_agent_sup:status(Sup) || Sup <- Ws] end),
_ = kz_util:spawn(fun() -> lists:foreach(fun acdc_agent_sup:status/1, Ws) end),
'ok'.

-spec new(kz_json:object()) -> sup_startchild_ret().
-spec new(ne_binary(), ne_binary()) -> sup_startchild_ret().
new(JObj) ->
case find_agent_supervisor(kz_doc:account_id(JObj)
,kz_doc:id(JObj)
)
of
case find_agent_supervisor(kz_doc:account_id(JObj), kz_doc:id(JObj)) of
'undefined' -> supervisor:start_child(?SERVER, [JObj]);
P when is_pid(P) -> lager:debug("agent already started here: ~p", [P])
end.
Expand Down
20 changes: 7 additions & 13 deletions applications/acdc/src/acdc_maintenance.erl
Original file line number Diff line number Diff line change
Expand Up @@ -87,8 +87,7 @@ current_queues(AccountId) ->

log_current_queues(Agents) ->
io:format(" ~35s | ~s~n", [<<"Agent ID">>, <<"Queue IDs">>]),
_ = [log_current_queue(Agent) || Agent <- Agents],
'ok'.
lists:foreach(fun log_current_queue/1, Agents).
log_current_queue(AgentSup) ->
AgentL = acdc_agent_sup:listener(AgentSup),
io:format(" ~35s | ~s~n", [acdc_agent_listener:id(AgentL)
Expand All @@ -104,8 +103,7 @@ current_agents(AccountId) ->
end.
log_current_agents(Queues) ->
io:format(" ~35s | ~s~n", [<<"Queue ID">>, <<"Agent IDs">>]),
_ = [log_current_agent(Queue) || Queue <- Queues],
'ok'.
lists:foreach(fun log_current_agent/1, Queues).
log_current_agent(QueueSup) ->
QueueM = acdc_queue_sup:manager(QueueSup),
{_AccountId, QueueId} = acdc_queue_manager:config(QueueM),
Expand Down Expand Up @@ -209,7 +207,7 @@ migrate_to_acdc_db() ->
{'ok', Accounts} = kz_datamgr:all_docs(?KZ_ACDC_DB),
_ = [maybe_remove_acdc_account(kz_doc:id(Account)) || Account <- Accounts],
io:format("removed any missing accounts from ~s~n", [?KZ_ACDC_DB]),
_ = [migrate_to_acdc_db(Acct) || Acct <- kapps_util:get_all_accounts('raw')],
lists:foreach(fun migrate_to_acdc_db/1, kapps_util:get_all_accounts('raw')),
io:format("migration complete~n").

-spec maybe_remove_acdc_account(ne_binary()) -> 'ok'.
Expand Down Expand Up @@ -322,10 +320,8 @@ queues_detail() ->
acdc_queues_sup:status().
queues_detail(AcctId) ->
kz_util:put_callid(?MODULE),
_ = [acdc_queue_sup:status(S)
|| S <- acdc_queues_sup:find_acct_supervisors(AcctId)
],
'ok'.
lists:foreach(fun acdc_queue_sup:status/1
,acdc_queues_sup:find_acct_supervisors(AcctId)).
queue_detail(AcctId, QueueId) ->
case acdc_queues_sup:find_queue_supervisor(AcctId, QueueId) of
'undefined' -> lager:info("no queue ~s in account ~s", [QueueId, AcctId]);
Expand Down Expand Up @@ -410,10 +406,8 @@ agents_detail() ->
acdc_agents_sup:status().
agents_detail(AcctId) ->
kz_util:put_callid(?MODULE),
_ = [acdc_agent_sup:status(S)
|| S <- acdc_agents_sup:find_acct_supervisors(AcctId)
],
'ok'.
lists:foreach(fun acdc_agent_sup:status/1
,acdc_agents_sup:find_acct_supervisors(AcctId)).
agent_detail(AcctId, AgentId) ->
kz_util:put_callid(?MODULE),
case acdc_agents_sup:find_agent_supervisor(AcctId, AgentId) of
Expand Down
2 changes: 1 addition & 1 deletion applications/acdc/src/acdc_queues_sup.erl
Original file line number Diff line number Diff line change
Expand Up @@ -80,7 +80,7 @@ find_queue_supervisor(AcctId, QueueId, [Super|Rest]) ->
status() ->
lager:info("ACDc Queues Status"),
Ws = workers(),
_ = kz_util:spawn(fun() -> [acdc_queue_sup:status(Sup) || Sup <- Ws] end),
_ = kz_util:spawn(fun() -> lists:foreach(fun acdc_queue_sup:status/1, Ws) end),
'ok'.

-spec queues_running() -> [{pid(), any()}].
Expand Down
5 changes: 2 additions & 3 deletions applications/blackhole/src/blackhole.hrl
Original file line number Diff line number Diff line change
Expand Up @@ -17,8 +17,7 @@

-type bh_subscribe_result() :: {'ok', bh_context:context()} | {'error', ne_binary()}.

-record(bh_context, {
auth_token = <<>> :: api_binary() | '_'
-record(bh_context, {auth_token = <<>> :: api_binary() | '_'
,auth_account_id :: api_binary() | '_'
,account_id :: api_binary() | '_'
,bindings = [] :: ne_binaries() | '_'
Expand All @@ -31,7 +30,7 @@
,destination = kz_util:node_hostname() :: ne_binary() | '_'
,source :: api_binary() | '_'
,binding :: api_binary() | '_'
}).
}).

-define(BLACKHOLE_HRL, 'true').

Expand Down
8 changes: 4 additions & 4 deletions applications/blackhole/src/blackhole_bindings.erl
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,9 @@

-include("blackhole.hrl").

-define(BH_MODULES,
kapps_config:get(?BLACKHOLE_CONFIG_CAT, <<"autoload_modules">>, ?DEFAULT_MODULES)).

-type payload() :: bh_context:context() | ne_binary().

%%%===================================================================
Expand Down Expand Up @@ -175,10 +178,7 @@ modules_loaded() -> kazoo_bindings:modules_loaded().
init() ->
lager:debug("initializing blackhole bindings"),
kz_util:put_callid(?LOG_SYSTEM_ID),
_ = [init_mod(Mod)
|| Mod <- kapps_config:get(?BLACKHOLE_CONFIG_CAT, <<"autoload_modules">>, ?DEFAULT_MODULES)
],
'ok'.
lists:foreach(fun init_mod/1, ?BH_MODULES).

init_mod(ModuleName) ->
lager:debug("initializing module: ~p", [ModuleName]),
Expand Down
8 changes: 4 additions & 4 deletions applications/cdr/src/cdr_v3_migrate_lib.erl
Original file line number Diff line number Diff line change
Expand Up @@ -142,8 +142,7 @@ delete_test_accounts() ->
{'error', _E} -> lager:debug("error retrieving accounts: ~p", [_E]);
[] -> 'ok';
Accounts ->
_ = [maybe_delete_test_account(AccountDb) || AccountDb <- Accounts],
'ok'
lists:foreach(fun maybe_delete_test_account/1, Accounts)
end.

-spec maybe_get_migrate_account(account_db()) -> 'false' | kz_json:object().
Expand All @@ -153,8 +152,9 @@ maybe_get_migrate_account(AccountDb) ->
[] -> 'false';
{'ok', Results} ->
[kz_json:get_value(<<"doc">>, Result)
|| Result <- Results
,matches_realm(kz_json:get_value(<<"key">>, Result))]
|| Result <- Results,
matches_realm(kz_json:get_value(<<"key">>, Result))
]
end.

-spec matches_realm(ne_binary()) -> boolean().
Expand Down
10 changes: 4 additions & 6 deletions applications/crossbar/src/crossbar_bindings.erl
Original file line number Diff line number Diff line change
Expand Up @@ -196,16 +196,14 @@ start_link() ->
-spec init() -> 'ok'.
init() ->
lager:debug("initializing bindings"),

kz_util:put_callid(?LOG_SYSTEM_ID),
_ = [maybe_init_mod(Mod)
|| Mod <- crossbar_config:autoload_modules(?DEFAULT_MODULES)
],
'ok'.
lists:foreach(fun maybe_init_mod/1
,crossbar_config:autoload_modules(?DEFAULT_MODULES)).

-spec maybe_init_mod(ne_binary() | atom()) -> 'ok'.
maybe_init_mod(Mod) ->
case crossbar_init:start_mod(Mod) of
'ok' -> 'ok';
{'error', Error} -> lager:notice("failed to initialize ~s: ~p", [Mod, Error])
{'error', Error} ->
lager:notice("failed to initialize ~s: ~p", [Mod, Error])
end.
19 changes: 8 additions & 11 deletions applications/crossbar/src/crossbar_freeswitch.erl
Original file line number Diff line number Diff line change
Expand Up @@ -271,8 +271,7 @@ process_realm(Realm, Dir, Module) ->
lager:debug("wrote file ~s", [XMLFile]);
{'error', E} ->
lager:debug("error rendering template ~s for realm ~s: ~p"
,[Module, Realm, E]
)
,[Module, Realm, E])
end.

%% @private
Expand Down Expand Up @@ -302,8 +301,7 @@ crawl_numbers_db(NumberDb) ->
maybe_export_numbers(Db, Numbers);
{'error', _R} ->
lager:debug("error getting number docs from ~s: ~p"
,[NumberDb, _R]
)
,[NumberDb, _R])
catch
_E:_R ->
lager:debug("~s getting number docs from ~s: ~p"
Expand All @@ -313,11 +311,11 @@ crawl_numbers_db(NumberDb) ->
-spec get_numbers(kz_json:objects()) -> ne_binaries().
get_numbers(JObjs) ->
[Number
|| JObj <- JObjs
,case (Number = kz_doc:id(JObj)) of
<<"_design/", _/binary>> -> 'false';
_Else -> 'true'
end
|| JObj <- JObjs,
case (Number = kz_doc:id(JObj)) of
<<"_design/", _/binary>> -> 'false';
_Else -> 'true'
end
].

-spec maybe_export_numbers(ne_binary(), ne_binaries()) -> 'ok'.
Expand All @@ -331,8 +329,7 @@ maybe_export_numbers(Db, [Number|Numbers]) ->
);
{'error', _R} ->
lager:debug("error fetching number ~s from ~d: ~p"
,[Number, Db, _R]
)
,[Number, Db, _R])
end,
maybe_export_numbers(Db, Numbers).

Expand Down
13 changes: 6 additions & 7 deletions applications/crossbar/src/modules/cb_modules_util.erl
Original file line number Diff line number Diff line change
Expand Up @@ -572,11 +572,11 @@ take_sync_field(Context) ->
%% @public
-spec remove_plaintext_password(cb_context:context()) -> cb_context:context().
remove_plaintext_password(Context) ->
Doc = kz_json:delete_keys(
[<<"password">>,
<<"confirm_password">>
], cb_context:doc(Context)
),
Doc = kz_json:delete_keys([<<"password">>
,<<"confirm_password">>
]
,cb_context:doc(Context)
),
cb_context:set_doc(Context, Doc).

-type assignment_updates() :: [{ne_binary(), knm_number:knm_number_return()}].
Expand All @@ -590,8 +590,7 @@ apply_assignment_updates(Updates) ->

-spec log_assignment_updates(assignment_updates()) -> 'ok'.
log_assignment_updates(Updates) ->
_ = [log_assignment_update(Update) || Update <- Updates],
'ok'.
lists:foreach(fun log_assignment_update/1, Updates).

-spec log_assignment_update({ne_binary(), knm_number:knm_number_return()}) -> 'ok'.
log_assignment_update({DID, {'ok', _Number}}) ->
Expand Down
3 changes: 1 addition & 2 deletions applications/doodle/src/doodle_inbound_listener_sup.erl
Original file line number Diff line number Diff line change
Expand Up @@ -42,8 +42,7 @@ start_inbound_listener(Connection) ->

-spec start_listeners() -> 'ok'.
start_listeners() ->
_ = [start_inbound_listener(C) || C <- connections()],
'ok'.
lists:foreach(fun start_inbound_listener/1, connections()).

%%--------------------------------------------------------------------
%% @public
Expand Down
6 changes: 2 additions & 4 deletions applications/ecallmgr/src/ecallmgr_fs_channels.erl
Original file line number Diff line number Diff line change
Expand Up @@ -892,12 +892,10 @@ cleanup_old_channels(MaxAge) ->

-spec hangup_old_channels(old_channels()) -> 'ok'.
hangup_old_channels(OldChannels) ->
_ = [hangup_old_channel(C) || C <- OldChannels],
'ok'.
lists:foreach(fun hangup_old_channel/1, OldChannels).

-spec hangup_old_channel(old_channel()) -> 'ok'.
hangup_old_channel([UUID, Node, Started]) ->
lager:debug("killing channel ~s on ~s, started ~s"
,[UUID, Node, kz_util:pretty_print_datetime(Started)]
),
,[UUID, Node, kz_util:pretty_print_datetime(Started)]),
freeswitch:api(Node, 'uuid_kill', UUID).
4 changes: 2 additions & 2 deletions applications/ecallmgr/src/ecallmgr_fs_node.erl
Original file line number Diff line number Diff line change
Expand Up @@ -599,7 +599,7 @@ was_not_successful_cmd(_) -> 'true'.
-spec print_api_responses(cmd_results()) -> 'ok'.
print_api_responses(Res) ->
lager:debug("start cmd results:"),
_ = [ print_api_response(ApiRes) || ApiRes <- lists:flatten(Res)],
lists:foreach(fun print_api_response/1, lists:flatten(Res)),
lager:debug("end cmd results").

-spec print_api_response(cmd_result()) -> 'ok'.
Expand All @@ -620,7 +620,7 @@ channels_as_json(Node) ->
Keys = binary:split(Header, <<"|||">>, ['global']),
[kz_json:from_list(lists:zip(Keys, Values))
|| Line <- Rest,
((Values = binary:split(Line, <<"|||">>, ['global'])) =/= [Line])
(Values = binary:split(Line, <<"|||">>, ['global'])) =/= [Line]
]
end;
{'error', _} -> []
Expand Down
16 changes: 6 additions & 10 deletions applications/ecallmgr/src/ecallmgr_maintenance.erl
Original file line number Diff line number Diff line change
Expand Up @@ -422,17 +422,15 @@ channel_details(UUID) ->

-spec sync_channels() -> 'ok'.
sync_channels() ->
_ = [ecallmgr_fs_node:sync_channels(Srv)
|| Srv <- gproc:lookup_pids({'p', 'l', 'fs_node'})
],
'ok'.
lists:foreach(fun ecallmgr_fs_node:sync_channels/1
,gproc:lookup_pids({'p', 'l', 'fs_node'})).

-spec sync_channels(text()) -> 'ok'.
sync_channels(Node) ->
N = kz_util:to_atom(Node, 'true'),
_ = [ecallmgr_fs_node:sync_channels(Srv)
|| Srv <- gproc:lookup_pids({'p', 'l', 'fs_node'})
,ecallmgr_fs_node:fs_node(Srv) =:= N
|| Srv <- gproc:lookup_pids({'p', 'l', 'fs_node'}),
ecallmgr_fs_node:fs_node(Srv) =:= N
],
'ok'.

Expand All @@ -458,10 +456,8 @@ conference_details(UUID) ->

-spec sync_conferences() -> 'ok'.
sync_conferences() ->
_ = [ecallmgr_fs_conferences:sync_node(N)
|| N <- ecallmgr_fs_nodes:connected()
],
'ok'.
lists:foreach(fun ecallmgr_fs_conferences:sync_node/1
,ecallmgr_fs_nodes:connected()).

-spec sync_conferences(text()) -> 'ok'.
sync_conferences(Node) ->
Expand Down
21 changes: 11 additions & 10 deletions applications/hotornot/src/hotornot_maintenance.erl
Original file line number Diff line number Diff line change
Expand Up @@ -15,10 +15,12 @@

-include("hotornot.hrl").

-define(LOCAL_SUMMARY_ROW_FORMAT, " ~45.s | ~9.s | ~9.s | ~9.s | ~9.s | ~9.s | ~15.s |~n").
-define(LOCAL_SUMMARY_HEADER, io:format(?LOCAL_SUMMARY_ROW_FORMAT, [<<"RATE NAME">>, <<"COST">>, <<"INCREMENT">>, <<"MINIMUM">>
,<<"SURCHARGE">>, <<"WEIGHT">>, <<"PREFIX">>
])).
-define(LOCAL_SUMMARY_ROW_FORMAT,
" ~45.s | ~9.s | ~9.s | ~9.s | ~9.s | ~9.s | ~15.s |~n").
-define(LOCAL_SUMMARY_HEADER,
io:format(?LOCAL_SUMMARY_ROW_FORMAT, [<<"RATE NAME">>, <<"COST">>, <<"INCREMENT">>, <<"MINIMUM">>
,<<"SURCHARGE">>, <<"WEIGHT">>, <<"PREFIX">>
])).

-spec local_summary() -> 'ok'.
local_summary() ->
Expand All @@ -35,7 +37,7 @@ rates_for_did(DID, Direction, RouteOptions) when is_list(RouteOptions) ->
{'ok', Rates} ->
io:format("Candidates:~n", []),
?LOCAL_SUMMARY_HEADER,
_ = [print_rate(R) || R <- Rates],
lists:foreach(fun print_rate/1, Rates),

print_matching(hon_util:matching_rates(Rates, DID, Direction, RouteOptions))
end;
Expand All @@ -52,11 +54,10 @@ print_matching(Matching) ->
[Winning|Sorted] = hon_util:sort_rates(Matching),
Name = kz_json:get_value(<<"rate_name">>, Winning),

_ = [print_rate(R)
|| R <- [kz_json:set_value(<<"rate_name">>, <<"* ", Name/binary>>, Winning)
| Sorted]
],
'ok'.
lists:foreach(fun print_rate/1
,[kz_json:set_value(<<"rate_name">>, <<"* ", Name/binary>>, Winning)
| Sorted
]).

-spec rates_between(ne_binary(), ne_binary()) -> 'ok'.
rates_between(Pre, Post) ->
Expand Down
2 changes: 1 addition & 1 deletion applications/tasks/src/knm_number_crawler.erl
Original file line number Diff line number Diff line change
Expand Up @@ -65,7 +65,7 @@ stop() ->
crawl_numbers() ->
kz_util:put_callid(?MODULE),
lager:debug("beginning a number crawl"),
_ = [crawl_number_db(Db) || Db <- knm_util:get_all_number_dbs()],
lists:foreach(fun crawl_number_db/1, knm_util:get_all_number_dbs()),
lager:debug("finished the number crawl").

%%%===================================================================
Expand Down
4 changes: 1 addition & 3 deletions applications/webhooks/src/webhooks_init.erl
Original file line number Diff line number Diff line change
Expand Up @@ -62,9 +62,7 @@ init_master_account_db(MasterAccountDb) ->

-spec init_modules() -> 'ok'.
init_modules() ->
_ = [init_module(Mod)
|| Mod <- existing_modules()
],
lists:foreach(fun init_module/1, existing_modules()),
lager:debug("finished initializing modules").

-spec init_module(atom()) -> 'ok'.
Expand Down
Loading

0 comments on commit b6d8019

Please sign in to comment.