1
0
Fork 0
mirror of https://github.com/processone/ejabberd synced 2025-10-03 09:49:18 +02:00

Make delete_old_mam_messages_batch work with sqlite

This commit is contained in:
Paweł Chmielowski 2025-04-17 14:21:25 +02:00
parent ef754939c4
commit 45e7d8426d

View file

@ -213,21 +213,37 @@ count_messages_to_delete(ServerHost, TimeStamp, Type) ->
delete_old_messages_batch(ServerHost, TimeStamp, Type, Batch) ->
TS = misc:now_to_usec(TimeStamp),
Res =
case Type of
all ->
ejabberd_sql:sql_query(
ServerHost,
?SQL("delete from archive"
" where timestamp < %(TS)d and %(ServerHost)H limit %(Batch)d"));
_ ->
SType = misc:atom_to_binary(Type),
ejabberd_sql:sql_query(
ServerHost,
?SQL("delete from archive"
" where timestamp < %(TS)d"
" and kind=%(SType)s"
" and %(ServerHost)H limit %(Batch)d"))
end,
case Type of
all ->
ejabberd_sql:sql_query(
ServerHost,
fun(sqlite, _) ->
ejabberd_sql:sql_query_t(
?SQL("delete from archive where rowid in "
"(select rowid from archive where timestamp < %(TS)d and %(ServerHost)H limit %(Batch)d)"));
(_, _) ->
ejabberd_sql:sql_query_t(
?SQL("delete from archive"
" where timestamp < %(TS)d and %(ServerHost)H limit %(Batch)d"))
end);
_ ->
SType = misc:atom_to_binary(Type),
ejabberd_sql:sql_query(
ServerHost,
fun(sqlire,_)->
ejabberd_sql:sql_query_t(
?SQL("delete from archive where rowid in ("
" select rowid from archive where timestamp < %(TS)d"
" and kind=%(SType)s"
" and %(ServerHost)H limit %(Batch)d)"));
(_,_)->
ejabberd_sql:sql_query_t(
?SQL("delete from archive"
" where timestamp < %(TS)d"
" and kind=%(SType)s"
" and %(ServerHost)H limit %(Batch)d"))
end)
end,
case Res of
{updated, Count} ->
{ok, Count};