aboutsummaryrefslogtreecommitdiffstats
path: root/plugins/mod_pep.lua
diff options
context:
space:
mode:
authorKim Alvefur <zash@zash.se>2019-05-30 15:16:56 +0200
committerKim Alvefur <zash@zash.se>2019-05-30 15:16:56 +0200
commitcabd5216b4de1471e62f4b859b634863e6ea2512 (patch)
tree7b49c4a49a6e2872a395bd4d269238c15b2f337c /plugins/mod_pep.lua
parent5cc63a416a1552da3259418db96d63af12079651 (diff)
downloadprosody-cabd5216b4de1471e62f4b859b634863e6ea2512.tar.gz
prosody-cabd5216b4de1471e62f4b859b634863e6ea2512.zip
mod_pep: Handle presence based subscription outside of util.pubsub (fixes #1372)
Subscriptions were updated for each incoming presence stanza from contacts. Each subscription change triggered a configuration save, which would filter out the presence based subscriptions and usually end up replacing the existing data with identical data. With many subscribed nodes this adds up to a fair bit of IO bound work that is avoided by keeping them separate.
Diffstat (limited to 'plugins/mod_pep.lua')
-rw-r--r--plugins/mod_pep.lua54
1 files changed, 17 insertions, 37 deletions
diff --git a/plugins/mod_pep.lua b/plugins/mod_pep.lua
index 7a4aac2b..f60f84c9 100644
--- a/plugins/mod_pep.lua
+++ b/plugins/mod_pep.lua
@@ -90,21 +90,6 @@ local function nodestore(username)
return data, err;
end
function store:set(node, data)
- if data then
- -- Save the data without subscriptions
- local subscribers = {};
- for jid, sub in pairs(data.subscribers) do
- if type(sub) ~= "table" or not sub.presence then
- subscribers[jid] = sub;
- end
- end
- data = {
- name = data.name;
- config = data.config;
- affiliations = data.affiliations;
- subscribers = subscribers;
- };
- end
return node_config:set(username, node, data);
end
function store:users()
@@ -151,7 +136,23 @@ local function get_broadcaster(username)
end
message:add_child(item);
end
+
+ local broadcast_to = {};
for jid in pairs(jids) do
+ broadcast_to[jid] = true;
+ end
+
+ local service_recipients = recipients[username];
+ if service_recipients then
+ local service = services[username];
+ for recipient, nodes in pairs(service_recipients) do
+ if nodes:contains(node) and service:may(node, recipient, "subscribe") then
+ broadcast_to[recipient] = true;
+ end
+ end
+ end
+
+ for jid in pairs(broadcast_to) do
module:log("debug", "Sending notification to %s from %s: %s", jid, user_bare, tostring(item));
message.attr.to = jid;
module:send(message);
@@ -160,20 +161,6 @@ local function get_broadcaster(username)
return simple_broadcast;
end
-local function on_node_creation(event)
- local service = event.service;
- local node = event.node;
- local username = service.config.pep_username;
-
- local service_recipients = recipients[username];
- if not service_recipients then return; end
-
- for recipient, nodes in pairs(service_recipients) do
- if nodes:contains(node) then
- service:add_subscription(node, recipient, recipient, { presence = true });
- end
- end
-end
function get_pep_service(username)
module:log("debug", "get_pep_service(%q)", username);
@@ -233,10 +220,6 @@ function get_pep_service(username)
return service;
end
-module:hook("item-added/pep-service", function (event)
- local service = event.item.service;
- module:hook_object_event(service.events, "node-created", on_node_creation);
-end);
function handle_pubsub_iq(event)
local origin, stanza = event.origin, event.stanza;
@@ -303,12 +286,9 @@ local function update_subscriptions(recipient, service_name, nodes)
end
local service = get_pep_service(service_name);
- for node in current - nodes do
- service:remove_subscription(node, recipient, recipient);
- end
for node in nodes - current do
- if service:add_subscription(node, recipient, recipient, { presence = true }) then
+ if service:may(node, recipient, "subscribe") then
resend_last_item(recipient, node, service);
end
end