fix: Add users-table cleanup

This commit is contained in:
Yaroslav Rogov 2021-06-22 16:24:42 +03:00
parent c3a843887b
commit 5665ee6df2
No known key found for this signature in database
GPG Key ID: 5159F2A85653816B

View File

@ -508,11 +508,31 @@ unlock_version(Version, TS) ->
cleanup() ->
Snaps = get_all_snaps(),
Sorted = lists:keysort(#snap.last_access, Snaps),
cleanup_users(Snaps),
case do_get_last_version() of
{ok, HeadVersion} -> cleanup(Sorted, HeadVersion);
_ -> ok
end.
cleanup_users(Snaps) ->
VersionMap =
lists:foldl(
fun(#snap{vsn = Version}, Acc) -> sets:add_element(Version, Acc) end,
sets:new(),
Snaps
),
ets:foldl(
fun(Rec = #user{vsn = Version, pid = Pid, requested_at = '_'}, _) ->
case sets:is_element(Version, VersionMap) andalso erlang:is_alive(Pid) of
true -> ok;
false -> ets:delete_object(?USERS_TABLE, Rec)
end
end,
ok,
?USERS_TABLE
).
-spec cleanup([snap()], dmt_client:vsn()) -> ok.
cleanup([], _HeadVersion) ->
ok;