]> granicus.if.org Git - ejabberd/commitdiff
Added MySQL support for delete_old_messages (offline) command.
authorJerome Sautret <jerome.sautret@process-one.net>
Fri, 13 Mar 2015 17:29:57 +0000 (18:29 +0100)
committerChristophe Romain <christophe.romain@process-one.net>
Fri, 20 Mar 2015 09:40:19 +0000 (10:40 +0100)
sql/mysql.sql
src/mod_offline.erl

index 64f54ba70c15191d616e1721e09dbba1f27d98d5..8557d0804f4fe20c5423ce5937981f42bf0c250a 100644 (file)
@@ -79,6 +79,7 @@ CREATE TABLE spool (
 ) ENGINE=InnoDB CHARACTER SET utf8;
 
 CREATE INDEX i_despool USING BTREE ON spool(username);
+CREATE INDEX i_spool_created_at USING BTREE ON spool(created_at);
 
 CREATE TABLE vcard (
     username varchar(250) PRIMARY KEY,
index d345140e27046520b98034b1593e3701c35a98b0..d907482554a4dbb5da734071a9838ac6a247663a 100644 (file)
@@ -236,7 +236,7 @@ store_offline_msg(Host, {User, _}, Msgs, Len, MaxOfflineMsgs,
                     Len + count_offline_messages(User, Host);
                true -> 0
             end,
-    if 
+    if
         Count > MaxOfflineMsgs ->
             discard_warn_sender(Msgs);
         true ->
@@ -561,7 +561,19 @@ remove_old_messages(Days, _LServer, mnesia) ->
                             ok, offline_msg)
        end,
     mnesia:transaction(F);
-remove_old_messages(_Days, _LServer, odbc) ->
+
+remove_old_messages(Days, LServer, odbc) ->
+    case catch ejabberd_odbc:sql_query(
+                LServer,
+                [<<"DELETE FROM spool"
+                  " WHERE created_at < "
+                  "DATE_SUB(CURDATE(), INTERVAL ">>,
+                 integer_to_list(Days), <<" DAY);">>]) of
+       {updated, N} ->
+           ?INFO_MSG("~p message(s) deleted from offline spool", [N]);
+       _Error ->
+           ?ERROR_MSG("Cannot delete message in offline spool: ~p", [_Error])
+    end,
     {atomic, ok};
 remove_old_messages(_Days, _LServer, riak) ->
     {atomic, ok}.