25
1
mirror of https://github.com/processone/ejabberd.git synced 2024-12-20 17:27:00 +01:00

Don't store xdata() in Mnesia table

This commit is contained in:
Evgeniy Khramtsov 2017-10-27 11:46:37 +03:00
parent 484e5de072
commit 24df1262bb
3 changed files with 39 additions and 20 deletions

View File

@ -21,4 +21,4 @@
timestamp = p1_time_compat:timestamp() :: erlang:timestamp(),
service = {<<"">>, <<"">>, <<"">>} :: ljid(),
node = <<"">> :: binary(),
xdata = #xdata{} :: xdata()}).
xml = undefined :: xmlel()}).

View File

@ -31,7 +31,7 @@
%% API
-export([init/2, store_session/6, lookup_session/4, lookup_session/3,
lookup_sessions/3, lookup_sessions/2, lookup_sessions/1,
delete_session/3, delete_old_sessions/2]).
delete_session/3, delete_old_sessions/2, transform/1]).
-include_lib("stdlib/include/ms_transform.hrl").
-include("logger.hrl").
@ -61,7 +61,7 @@ store_session(LUser, LServer, TS, PushJID, Node, XData) ->
timestamp = TS,
service = PushLJID,
node = Node,
xdata = XData})
xml = encode_xdata(XData)})
end,
case mnesia:transaction(F) of
{atomic, ok} ->
@ -83,8 +83,8 @@ lookup_session(LUser, LServer, PushJID, Node) ->
Rec
end),
case mnesia:dirty_select(push_session, MatchSpec) of
[#push_session{timestamp = TS, xdata = XData}] ->
{ok, {TS, PushLJID, Node, XData}};
[#push_session{timestamp = TS, xml = El}] ->
{ok, {TS, PushLJID, Node, decode_xdata(El)}};
[] ->
?DEBUG("No push session found for ~s@~s (~p, ~s)",
[LUser, LServer, PushJID, Node]),
@ -100,8 +100,8 @@ lookup_session(LUser, LServer, TS) ->
Rec
end),
case mnesia:dirty_select(push_session, MatchSpec) of
[#push_session{service = PushLJID, node = Node, xdata = XData}] ->
{ok, {TS, PushLJID, Node, XData}};
[#push_session{service = PushLJID, node = Node, xml = El}] ->
{ok, {TS, PushLJID, Node, decode_xdata(El)}};
[] ->
?DEBUG("No push session found for ~s@~s (~p)",
[LUser, LServer, TS]),
@ -113,22 +113,18 @@ lookup_sessions(LUser, LServer, PushJID) ->
MatchSpec = ets:fun2ms(
fun(#push_session{us = {U, S}, service = P,
node = Node, timestamp = TS,
xdata = XData} = Rec)
xml = El} = Rec)
when U == LUser,
S == LServer,
P == PushLJID ->
{TS, PushLJID, Node, XData}
Rec
end),
{ok, mnesia:dirty_select(push_session, MatchSpec)}.
Records = mnesia:dirty_select(push_session, MatchSpec),
{ok, records_to_sessions(Records)}.
lookup_sessions(LUser, LServer) ->
Records = mnesia:dirty_read(push_session, {LUser, LServer}),
Clients = [{TS, PushLJID, Node, XData}
|| #push_session{timestamp = TS,
service = PushLJID,
node = Node,
xdata = XData} <- Records],
{ok, Clients}.
{ok, records_to_sessions(Records)}.
lookup_sessions(LServer) ->
MatchSpec = ets:fun2ms(
@ -136,11 +132,12 @@ lookup_sessions(LServer) ->
timestamp = TS,
service = PushLJID,
node = Node,
xdata = XData})
xml = El})
when S == LServer ->
{TS, PushLJID, Node, XData}
{TS, PushLJID, Node, El}
end),
{ok, mnesia:dirty_select(push_session, MatchSpec)}.
Records = mnesia:dirty_select(push_session, MatchSpec),
{ok, records_to_sessions(Records)}.
delete_session(LUser, LServer, TS) ->
MatchSpec = ets:fun2ms(
@ -180,6 +177,11 @@ delete_old_sessions(_LServer, Time) ->
{error, db_failure}
end.
transform({push_session, US, TS, Service, Node, XData}) ->
?INFO_MSG("Transforming push_session Mnesia table", []),
#push_session{us = US, timestamp = TS, service = Service,
node = Node, xml = encode_xdata(XData)}.
%%--------------------------------------------------------------------
%% Internal functions.
%%--------------------------------------------------------------------
@ -198,3 +200,20 @@ enforce_max_sessions({U, S} = US, Max) ->
true ->
ok
end.
decode_xdata(undefined) ->
undefined;
decode_xdata(El) ->
xmpp:decode(El).
encode_xdata(undefined) ->
undefined;
encode_xdata(XData) ->
xmpp:encode(XData).
records_to_sessions(Records) ->
[{TS, PushLJID, Node, decode_xdata(El)}
|| #push_session{timestamp = TS,
service = PushLJID,
node = Node,
xml = El} <- Records].

View File

@ -177,7 +177,7 @@ export(_Server) ->
timestamp = NowTS,
service = PushLJID,
node = Node,
xdata = XData})
xml = XData})
when LServer == Host ->
TS = misc:now_to_usec(NowTS),
Service = jid:encode(PushLJID),