25
1
mirror of https://github.com/processone/ejabberd.git synced 2024-11-20 16:15:59 +01:00

Don't fetch subscribers list in room_unused_*

This commit is contained in:
Paweł Chmielowski 2021-01-26 11:13:23 +01:00
parent bb87b6f948
commit b977320091
2 changed files with 25 additions and 2 deletions

View File

@ -852,6 +852,13 @@ get_all_rooms(Host) ->
end, #{}, OnlineRooms), end, #{}, OnlineRooms),
Mod = gen_mod:db_mod(ServerHost, mod_muc), Mod = gen_mod:db_mod(ServerHost, mod_muc),
DbRooms =
case erlang:function_exported(Mod, get_rooms_without_subscribers, 2) of
true ->
Mod:get_rooms_without_subscribers(ServerHost, Host);
_ ->
Mod:get_rooms(ServerHost, Host)
end,
StoredRooms = lists:filtermap( StoredRooms = lists:filtermap(
fun(#muc_room{name_host = {Room, _}, opts = Opts}) -> fun(#muc_room{name_host = {Room, _}, opts = Opts}) ->
case maps:is_key(Room, OnlineMap) of case maps:is_key(Room, OnlineMap) of
@ -860,7 +867,7 @@ get_all_rooms(Host) ->
_ -> _ ->
{true, {Room, Host, ServerHost, Opts}} {true, {Room, Host, ServerHost, Opts}}
end end
end, Mod:get_rooms(ServerHost, Host)), end, DbRooms),
OnlineRooms ++ StoredRooms. OnlineRooms ++ StoredRooms.
get_room_config(Room_pid) -> get_room_config(Room_pid) ->

View File

@ -36,7 +36,7 @@
get_online_rooms/3, count_online_rooms/2, rsm_supported/0, get_online_rooms/3, count_online_rooms/2, rsm_supported/0,
register_online_user/4, unregister_online_user/4, register_online_user/4, unregister_online_user/4,
count_online_rooms_by_user/3, get_online_rooms_by_user/3, count_online_rooms_by_user/3, get_online_rooms_by_user/3,
get_subscribed_rooms/3]). get_subscribed_rooms/3, get_rooms_without_subscribers/2]).
-export([set_affiliation/6, set_affiliations/4, get_affiliation/5, -export([set_affiliation/6, set_affiliations/4, get_affiliation/5,
get_affiliations/3, search_affiliation/4]). get_affiliations/3, search_affiliation/4]).
@ -155,6 +155,22 @@ can_use_nick(LServer, Host, JID, Nick) ->
_ -> true _ -> true
end. end.
get_rooms_without_subscribers(LServer, Host) ->
case catch ejabberd_sql:sql_query(
LServer,
?SQL("select @(name)s, @(opts)s from muc_room"
" where host=%(Host)s")) of
{selected, RoomOpts} ->
lists:map(
fun({Room, Opts}) ->
OptsD = ejabberd_sql:decode_term(Opts),
#muc_room{name_host = {Room, Host},
opts = mod_muc:opts_to_binary(OptsD)}
end, RoomOpts);
_Err ->
[]
end.
get_rooms(LServer, Host) -> get_rooms(LServer, Host) ->
case catch ejabberd_sql:sql_query( case catch ejabberd_sql:sql_query(
LServer, LServer,