chore: replace match_object with select/4

This commit is contained in:
zhongwencool 2022-12-05 17:00:38 +08:00
parent a7079b8c0e
commit c20b597e12
1 changed files with 7 additions and 5 deletions

View File

@ -92,20 +92,22 @@ init_bootstrap_apps() ->
end. end.
need_bootstrap() -> need_bootstrap() ->
{atomic, Res} = mnesia:transaction(fun() -> bootstrap_apps() =:= [] end), {atomic, Res} = mnesia:transaction(
fun() ->
Spec = [{#mqtt_app{id = '$1', desc = ?BOOTSTRAP_TAG, _ = '_'}, [], ['$1']}],
mnesia:select(mqtt_app, Spec, 1, read) =:= '$end_of_table'
end),
Res. Res.
clear_bootstrap_apps() -> clear_bootstrap_apps() ->
{atomic, ok} = {atomic, ok} =
mnesia:transaction(fun() -> mnesia:transaction(fun() ->
All = mnesia:match_object(mqtt_app, #mqtt_app{desc = ?BOOTSTRAP_TAG, _ = '_'}, read),
DeleteFun = fun(A) -> mnesia:delete_object(A) end, DeleteFun = fun(A) -> mnesia:delete_object(A) end,
lists:foreach(DeleteFun, bootstrap_apps()) lists:foreach(DeleteFun, All)
end), end),
ok. ok.
bootstrap_apps() ->
mnesia:match_object(mqtt_app, #mqtt_app{desc = ?BOOTSTRAP_TAG, _ = '_'}, read).
init_bootstrap_apps(undefined) -> ok; init_bootstrap_apps(undefined) -> ok;
init_bootstrap_apps(File) -> init_bootstrap_apps(File) ->
case file:open(File, [read, binary]) of case file:open(File, [read, binary]) of