# HG changeset patch # User Matthew Wild # Date 1686248386 -3600 # Node ID 3804ee5117ca8a206e0f1a03e3020d0708af1be4 # Parent 1249ab2f797c2a079656df80179ca565af5ef46b mod_firewall: Load marks from storage on demand rather than at login This ensures people who don't use marks, or use them infrequently, don't pay a perf cost on every resource bind. diff -r 1249ab2f797c -r 3804ee5117ca mod_firewall/marks.lib.lua --- a/mod_firewall/marks.lib.lua Thu Jun 08 19:15:12 2023 +0100 +++ b/mod_firewall/marks.lib.lua Thu Jun 08 19:19:46 2023 +0100 @@ -3,21 +3,14 @@ local user_sessions = prosody.hosts[module.host].sessions; -module:hook("resource-bind", function (event) - local session = event.session; - local username = session.username; - local user = user_sessions[username]; - local marks = user.firewall_marks; - if not marks then - marks = mark_storage:get(username) or {}; - user.firewall_marks = marks; -- luacheck: ignore 122 - end - session.firewall_marks = marks; -end); - module:hook("firewall/marked/user", function (event) local user = user_sessions[event.username]; local marks = user and user.firewall_marks; + if user and not marks then + -- Load marks from storage to cache on the user object + marks = mark_storage:get(event.username) or {}; + user.firewall_marks = marks; --luacheck: ignore 122 + end if marks then marks[event.mark] = event.timestamp; end