aboutsummaryrefslogtreecommitdiff
path: root/src/mod_muc_admin.erl
diff options
context:
space:
mode:
authorPaweł Chmielowski <pawel@process-one.net>2022-02-18 14:01:22 +0100
committerPaweł Chmielowski <pawel@process-one.net>2022-02-18 14:02:04 +0100
commitf86055378d6337c0e0b1555067f76e62f9265c8c (patch)
treed9edd10df8c9b5ed3a59a694383532cf65dd3c57 /src/mod_muc_admin.erl
parentCheck producing and starting releases (diff)
Optimize room_unused_* commands
Previously to check if hibernated room was old enough we had to fetch info about all rooms from database. Now we repurpose created_at field in sql to store that info, that allow us to have more efficient query just for it.
Diffstat (limited to '')
-rw-r--r--src/mod_muc_admin.erl17
1 files changed, 11 insertions, 6 deletions
diff --git a/src/mod_muc_admin.erl b/src/mod_muc_admin.erl
index 2db1d95f1..434559001 100644
--- a/src/mod_muc_admin.erl
+++ b/src/mod_muc_admin.erl
@@ -858,7 +858,7 @@ rooms_report(Method, Action, Service, Days) ->
muc_unused(Method, Action, Service, Last_allowed) ->
%% Get all required info about all existing rooms
- Rooms_all = get_all_rooms(Service),
+ Rooms_all = get_all_rooms(Service, erlang:system_time(microsecond) - Last_allowed*24*60*60*1000),
%% Decide which ones pass the requirements
Rooms_pass = decide_rooms(Method, Rooms_all, Last_allowed),
@@ -883,14 +883,14 @@ get_online_rooms(ServiceArg) ->
|| {RoomName, RoomHost, Pid} <- mod_muc:get_online_rooms(Host)]
end, Hosts).
-get_all_rooms(ServiceArg) ->
+get_all_rooms(ServiceArg, Timestamp) ->
Hosts = find_services(ServiceArg),
lists:flatmap(
fun(Host) ->
- get_all_rooms2(Host)
+ get_all_rooms2(Host, Timestamp)
end, Hosts).
-get_all_rooms2(Host) ->
+get_all_rooms2(Host, Timestamp) ->
ServerHost = ejabberd_router:host_of_route(Host),
OnlineRooms = get_online_rooms(Host),
OnlineMap = lists:foldl(
@@ -900,8 +900,11 @@ get_all_rooms2(Host) ->
Mod = gen_mod:db_mod(ServerHost, mod_muc),
DbRooms =
- case erlang:function_exported(Mod, get_rooms_without_subscribers, 2) of
- true ->
+ case {erlang:function_exported(Mod, get_rooms_without_subscribers, 2),
+ erlang:function_exported(Mod, get_hibernated_rooms_older_than, 3)} of
+ {_, true} ->
+ Mod:get_hibernated_rooms_older_than(ServerHost, Host, Timestamp);
+ {true, _} ->
Mod:get_rooms_without_subscribers(ServerHost, Host);
_ ->
Mod:get_rooms(ServerHost, Host)
@@ -956,6 +959,8 @@ decide_room(unused, {_Room_name, _Host, ServerHost, Room_pid}, Last_allowed) ->
case lists:keyfind(hibernation_time, 1, Opts) of
false ->
{NodeStartTime, 0};
+ {_, undefined} ->
+ {NodeStartTime, 0};
{_, T} ->
{T, 0}
end