25
1
mirror of https://github.com/processone/ejabberd.git synced 2024-11-24 16:23:40 +01:00

In offline export to SQL, first write all DELETE, later all INSERT (#1509)

This commit is contained in:
Badlop 2017-06-28 11:14:49 +02:00
parent aac190255b
commit 3c7c71cfa6

View File

@ -181,6 +181,13 @@ count_messages(LUser, LServer) ->
export(_Server) -> export(_Server) ->
[{offline_msg, [{offline_msg,
fun(Host, #offline_msg{us = {LUser, LServer}})
when LServer == Host ->
[?SQL("delete from spool where username=%(LUser)s;")];
(_Host, _R) ->
[]
end},
{offline_msg,
fun(Host, #offline_msg{us = {LUser, LServer}, fun(Host, #offline_msg{us = {LUser, LServer},
timestamp = TimeStamp, from = From, to = To, timestamp = TimeStamp, from = From, to = To,
packet = El}) packet = El})
@ -192,8 +199,7 @@ export(_Server) ->
Packet1, jid:make(LServer), Packet1, jid:make(LServer),
TimeStamp, <<"Offline Storage">>), TimeStamp, <<"Offline Storage">>),
XML = fxml:element_to_binary(xmpp:encode(Packet2)), XML = fxml:element_to_binary(xmpp:encode(Packet2)),
[?SQL("delete from spool where username=%(LUser)s;"), [?SQL("insert into spool(username, xml) values ("
?SQL("insert into spool(username, xml) values ("
"%(LUser)s, %(XML)s);")] "%(LUser)s, %(XML)s);")]
catch _:{xmpp_codec, Why} -> catch _:{xmpp_codec, Why} ->
?ERROR_MSG("failed to decode packet ~p of user ~s@~s: ~s", ?ERROR_MSG("failed to decode packet ~p of user ~s@~s: ~s",