perf: avoid unnecessary transaction
This commit is contained in:
parent
c28c6d1b7e
commit
8eab389ae1
|
@ -126,23 +126,16 @@ message_stats() ->
|
||||||
%% the broker.
|
%% the broker.
|
||||||
-spec session_open(emqx_types:clientid()) -> {_New :: boolean(), session_id(), [iterator_id()]}.
|
-spec session_open(emqx_types:clientid()) -> {_New :: boolean(), session_id(), [iterator_id()]}.
|
||||||
session_open(ClientID) ->
|
session_open(ClientID) ->
|
||||||
{atomic, Ret} =
|
case mnesia:dirty_read(?SESSION_TAB, ClientID) of
|
||||||
mria:transaction(
|
[#session{iterators = Iterators}] ->
|
||||||
?DS_SHARD,
|
IteratorIDs = maps:values(Iterators),
|
||||||
fun() ->
|
{false, ClientID, IteratorIDs};
|
||||||
case mnesia:read(?SESSION_TAB, ClientID) of
|
[] ->
|
||||||
[#session{iterators = Iterators}] ->
|
Iterators = #{},
|
||||||
IteratorIDs = maps:values(Iterators),
|
Session = #session{id = ClientID, iterators = Iterators},
|
||||||
{false, ClientID, IteratorIDs};
|
mria:dirty_write(?SESSION_TAB, Session),
|
||||||
[] ->
|
{true, ClientID, _IteratorIDs = []}
|
||||||
Iterators = #{},
|
end.
|
||||||
Session = #session{id = ClientID, iterators = Iterators},
|
|
||||||
mnesia:write(?SESSION_TAB, Session, write),
|
|
||||||
{true, ClientID, _IteratorIDs = []}
|
|
||||||
end
|
|
||||||
end
|
|
||||||
),
|
|
||||||
Ret.
|
|
||||||
|
|
||||||
%% @doc Called when a client reconnects with `clean session=true' or
|
%% @doc Called when a client reconnects with `clean session=true' or
|
||||||
%% during session GC
|
%% during session GC
|
||||||
|
|
Loading…
Reference in New Issue