From f63dcdb790232e95433f0b747fa3634e1ad4fe57 Mon Sep 17 00:00:00 2001 From: Holger Weiss Date: Thu, 21 Feb 2019 23:50:16 +0100 Subject: [PATCH] mod_mam_sql: Improve check for empty archive Avoid counting the messages of an archive to check whether it's empty. --- src/mod_mam_sql.erl | 16 +++++++--------- 1 file changed, 7 insertions(+), 9 deletions(-) diff --git a/src/mod_mam_sql.erl b/src/mod_mam_sql.erl index 48112842c..dee2cd7c7 100644 --- a/src/mod_mam_sql.erl +++ b/src/mod_mam_sql.erl @@ -268,15 +268,13 @@ export(_Server) -> is_empty_for_user(LUser, LServer) -> case ejabberd_sql:sql_query( LServer, - ?SQL("select @(count(*))d from archive" - " where username=%(LUser)s and %(LServer)H")) of - {selected, [{Res}]} -> - case Res of - 0 -> true; - _ -> false - end; - _ -> false - end. + ?SQL("select @(1)d from archive" + " where username=%(LUser)s and %(LServer)H limit 1")) of + {selected, [{1}]} -> + false; + _ -> + true + end. is_empty_for_room(LServer, LName, LHost) -> LUser = jid:encode({LName, LHost, <<>>}),