Hi, I have a Mnesia
table in my project, and there is a node on my OTP
which sends a request every 24 hours to clean expired data. but my table size on my disc is more than 1.8g and I Don’t want to use select
function, because this table is big and I need a way that is lazy like Stream.map
.
1 - how can delete expired data one by on after a timeout in my GenServer handel_info
? is this way right ?
or what is your suggestion to delete records lazy like Stream
2 - how can count all records on disc mnesia
, is there a lazy way to count ?
Thanks
Code which I am using and I think it is not lazy:
Mnesia.transaction(fn ->
Mnesia.select(Token, [{{Token, :"$1", :"$2", :"$3", :"$4", :"$5", :"$6"}, [], [:"$$"]}])
end)
|> case do
{:atomic, []} -> "no token"
{:atomic, data} ->
Enum.map(data, fn [id, _user_id, _token, access_expires_in, _create_time, _os] ->
if access_expires_in <= System.system_time(:second) do
Mnesia.dirty_delete(Token, id)
end
end)
_ -> "no token"
end