# HG changeset patch # User Matthew Wild # Date 1760015831 -3600 # Node ID 0570f1e2edf48558f6bbe4091165f99faef80cb1 # Parent c819b1b5a77550f1e3b3c26fefad81319e73cca0 mod_push2: Implement cache for user push registrations diff -r c819b1b5a775 -r 0570f1e2edf4 mod_push2/mod_push2.lua --- a/mod_push2/mod_push2.lua Fri Oct 03 11:53:29 2025 +0100 +++ b/mod_push2/mod_push2.lua Thu Oct 09 14:17:11 2025 +0100 @@ -20,6 +20,7 @@ local host_sessions = prosody.hosts[module.host].sessions local push2_registrations = module:open_store("push2_registrations", "keyval") +local push2_registrations_cache = require "prosody.util.cache".new(10); if _VERSION:match("5%.1") or _VERSION:match("5%.2") then module:log("warn", "This module may behave incorrectly on Lua before 5.3. It is recommended to upgrade to a newer Lua version.") @@ -114,6 +115,7 @@ if not push2_registrations:set(origin.username, registrations) then origin.send(st.error_reply(stanza, "wait", "internal-server-error")); else + push2_registrations_cache:set(origin.username, registrations); origin.push_registration_id = registration_id origin.push_registration = push_registration origin.first_hibernated_push = nil @@ -136,6 +138,7 @@ if not push2_registrations:set(origin.username, registrations) then origin.send(st.error_reply(stanza, "wait", "internal-server-error")); else + push2_registrations_cache:set(origin.username, nil); origin.push_registration_id = nil origin.push_registration = nil origin.first_hibernated_push = nil @@ -446,7 +449,11 @@ local function get_push_settings(stanza, session) local to = stanza.attr.to local node = to and jid.split(to) or session.username - local user_push_services = push2_registrations:get(node) + local user_push_services = push2_registrations_cache:get(node); + if not user_push_services then + user_push_services = push2_registrations:get(node); + push2_registrations_cache:set(node, user_push_services); + end return node, (user_push_services or {}) end