Software /
code /
prosody-modules
Changeset
5801:32d662015a84
mod_measure_active_users: Use the new mod_lastlog2 API
author | Matthew Wild <mwild1@gmail.com> |
---|---|
date | Wed, 06 Dec 2023 15:50:46 +0000 |
parents | 5800:34b46d157797 |
children | 5802:6ab9e1763f35 |
files | mod_measure_active_users/mod_measure_active_users.lua |
diffstat | 1 files changed, 4 insertions(+), 9 deletions(-) [+] |
line wrap: on
line diff
--- a/mod_measure_active_users/mod_measure_active_users.lua Wed Dec 06 15:45:44 2023 +0000 +++ b/mod_measure_active_users/mod_measure_active_users.lua Wed Dec 06 15:50:46 2023 +0000 @@ -9,6 +9,8 @@ -- Exclude disabled user accounts from the counts if usermanager supports that API local count_disabled = not module:get_option_boolean("measure_active_users_count_disabled", is_enabled == nil); +local get_last_active = module:depends("lastlog2").get_last_active; + function update_calculations() module:log("debug", "Calculating active users"); local host = module.host; @@ -21,15 +23,8 @@ active_d1, active_d7, active_d30 = active_d1 + 1, active_d7 + 1, active_d30 + 1; elseif count_disabled or is_enabled(username, host) then - local lastlog_data = store:get(username); - if lastlog_data then - -- Due to server restarts/crashes/etc. some events - -- may not always get recorded, so we'll just take the - -- latest as a sign of last activity - local last_active = math.max( - lastlog_data.login and lastlog_data.login.timestamp or 0, - lastlog_data.logout and lastlog_data.logout.timestamp or 0 - ); + local last_active = get_last_active(username); + if last_active then if now - last_active < 86400 then active_d1 = active_d1 + 1; end