changeset 2714:75b137cf869a

mod_cloud_notify: Don't notify for all smacks queued stanzas in a row Only send out a notification for the first unnotified stanza in the smacks queue, not for all queued stanzas in a row. Several notifications in the same second are useless and just cause server load on both ends.
author tmolitor <thilo@eightysoft.de>
date Mon, 08 May 2017 19:39:43 +0200
parents eea1d5bac451
children 9b43b7fc3558
files mod_cloud_notify/mod_cloud_notify.lua
diffstat 1 files changed, 18 insertions(+), 8 deletions(-) [+]
line wrap: on
line diff
--- a/mod_cloud_notify/mod_cloud_notify.lua	Mon May 08 19:36:37 2017 +0200
+++ b/mod_cloud_notify/mod_cloud_notify.lua	Mon May 08 19:39:43 2017 +0200
@@ -280,7 +280,7 @@
 -- publish on unacked smacks message
 local function process_smacks_stanza(stanza, session)
 	if session.push_identifier then
-		session.log("debug", "Invoking cloud handle_notify_request for smacks queued stanza");
+		session.log("debug", "Invoking cloud handle_notify_request() for smacks queued stanza");
 		local user_push_services = {[session.push_identifier] = session.push_settings};
 		local node = get_push_settings(stanza, session);
 		handle_notify_request(stanza, node, user_push_services);
@@ -288,14 +288,26 @@
 	return stanza;
 end
 
+local function process_smacks_queue(queue, session)
+	if not session.push_identifier then return; end
+	local user_push_services = {[session.push_identifier] = session.push_settings};
+	for i=1, #queue do
+		local stanza = queue[i];
+		local node = get_push_settings(stanza, session);
+		session.log("debug", "Invoking cloud handle_notify_request() for smacks queued stanza: %d", i);
+		if handle_notify_request(stanza, node, user_push_services) ~= 0 then
+			session.log("debug", "Cloud handle_notify_request() > 0, not notifying for other queued stanzas");
+			return;		-- only notify for one stanza in the queue, not for all in a row
+		end
+	end
+end
+
 -- smacks hibernation is started
 local function hibernate_session(event)
 	local session = event.origin;
 	local queue = event.queue;
 	-- process unacked stanzas
-	for i=1,#queue do
-		process_smacks_stanza(queue[i], session);
-	end
+	process_smacks_queue(queue, session);
 	-- process future unacked (hibernated) stanzas
 	filters.add_filter(session, "stanzas/out", process_smacks_stanza);
 end
@@ -318,9 +330,7 @@
 	local session = event.origin;
 	local queue = event.queue;
 	-- process unacked stanzas (handle_notify_request() will only send push requests for new stanzas)
-	for i=1,#queue do
-		process_smacks_stanza(queue[i], session);
-	end
+	process_smacks_queue(queue, session);
 end
 
 -- archive message added
@@ -350,7 +360,7 @@
 				end
 			end
 			if identifier_found then
-				identifier_found.log("debug", "Not notifying '%s' of new MAM stanza (session still alive)", identifier);
+				identifier_found.log("debug", "Not cloud notifying '%s' of new MAM stanza (session still alive)", identifier);
 			else
 				notify_push_sevices[identifier] = push_info;
 			end