diff options
author | Paweł Chmielowski <pawel@process-one.net> | 2022-05-02 15:05:55 +0200 |
---|---|---|
committer | Paweł Chmielowski <pawel@process-one.net> | 2022-05-02 15:05:55 +0200 |
commit | 6f11210edd7623a6bb19a33e5d8fb8100facad20 (patch) | |
tree | 4e00bb6bd1a7539300f9603163f46161cc115196 /src/mod_mam.erl | |
parent | Simplify rules for choosing jiffy version (diff) |
Implement batch operations in mnesia backend
Diffstat (limited to 'src/mod_mam.erl')
-rw-r--r-- | src/mod_mam.erl | 28 |
1 files changed, 21 insertions, 7 deletions
diff --git a/src/mod_mam.erl b/src/mod_mam.erl index fd292736..0288e2d5 100644 --- a/src/mod_mam.erl +++ b/src/mod_mam.erl @@ -578,13 +578,27 @@ delete_old_messages_batch(Server, Type, Days, BatchSize, Rate) when Type == <<"c TypeA = misc:binary_to_atom(Type), LServer = jid:nameprep(Server), Mod = gen_mod:db_mod(LServer, ?MODULE), - case ejabberd_batch:register_task({mam, LServer}, 0, Rate, {LServer, TypeA, TimeStamp, BatchSize}, - fun({L, T, St, B} = S) -> - case Mod:delete_old_messages_batch(L, St, T, B) of - {ok, Count} -> - {ok, S, Count}; - {error, _} = E -> - E + + case ejabberd_batch:register_task({mam, LServer}, 0, Rate, {LServer, TypeA, TimeStamp, BatchSize, none}, + fun({L, T, St, B, IS} = S) -> + case {erlang:function_exported(Mod, remove_old_messages_batch, 4), + erlang:function_exported(Mod, remove_old_messages_batch, 5)} of + {true, _} -> + case Mod:delete_old_messages_batch(L, St, T, B) of + {ok, Count} -> + {ok, S, Count}; + {error, _} = E -> + E + end; + {_, true} -> + case Mod:remove_old_messages_batch(L, St, T, B, IS) of + {ok, IS2, Count} -> + {ok, {L, St, T, B, IS2}, Count}; + {error, _} = E -> + E + end; + _ -> + {error, not_implemented_for_backend} end end) of ok -> |