diff options
author | Paweł Chmielowski <pchmielowski@process-one.net> | 2020-11-18 17:14:28 +0100 |
---|---|---|
committer | Paweł Chmielowski <pchmielowski@process-one.net> | 2020-11-18 17:14:28 +0100 |
commit | c2a3f037bb6e6651ffb2df6ad093cb5a2cb06b61 (patch) | |
tree | 1639fe924b8b6a2fc85d5f4905cd1585550b3441 /src/mod_muc_admin.erl | |
parent | We don't use persistent field in decide_room (diff) |
Update muc_room just_created timestamp when message is received
This together with last history message is used by room_unused_* command
to determine for how long room was not used, this change allow us to skip
checking history, and works even when history is disabled.
Diffstat (limited to 'src/mod_muc_admin.erl')
-rw-r--r-- | src/mod_muc_admin.erl | 38 |
1 files changed, 13 insertions, 25 deletions
diff --git a/src/mod_muc_admin.erl b/src/mod_muc_admin.erl index 77ad47f1..f818dd1e 100644 --- a/src/mod_muc_admin.erl +++ b/src/mod_muc_admin.erl @@ -874,41 +874,29 @@ decide_rooms(Method, Rooms, Last_allowed) -> decide_room(unused, {_Room_name, _Host, _ServerHost, Room_pid}, Last_allowed) -> NodeStartTime = erlang:system_time(microsecond) - 1000000*(erlang:monotonic_time(second)-ejabberd_config:get_node_start()), - {Just_created, Num_users, History} = + {Just_created, Num_users} = case Room_pid of Pid when is_pid(Pid) -> S = get_room_state(Room_pid), {S#state.just_created, - maps:size(S#state.users), - (S#state.history)#lqueue.queue}; + maps:size(S#state.users)}; Opts -> case lists:keyfind(hibernation_time, 1, Opts) of false -> - {NodeStartTime, 0, p1_queue:new()}; + {NodeStartTime, 0}; {_, T} -> - {T, 0, p1_queue:new()} + {T, 0} end end, - Ts_now = calendar:universal_time(), - {Has_hist, Last} = case p1_queue:is_empty(History) of - true when Just_created == true -> - {false, 0}; - true -> - Ts_diff = (erlang:system_time(microsecond) - - Just_created) div 1000000, - {false, Ts_diff}; - false -> - Last_message = get_queue_last(History), - Ts_last = calendar:now_to_universal_time( - element(4, Last_message)), - Ts_diff = - calendar:datetime_to_gregorian_seconds(Ts_now) - - calendar:datetime_to_gregorian_seconds(Ts_last), - {true, Ts_diff} - end, - case {Just_created, Num_users, Has_hist, seconds_to_days(Last)} of - {JC, 0, _, Last_days} - when (Last_days >= Last_allowed) and (JC /= true) -> + Last = case Just_created of + true -> + 0; + _ -> + (erlang:system_time(microsecond) + - Just_created) div 1000000 + end, + case {Num_users, seconds_to_days(Last)} of + {0, Last_days} when (Last_days >= Last_allowed) -> true; _ -> false |