Mercurial > prosody-modules
comparison mod_cloud_notify/mod_cloud_notify.lua @ 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 | d89ab70808f6 |
children | fff185e7ab73 |
comparison
equal
deleted
inserted
replaced
2713:eea1d5bac451 | 2714:75b137cf869a |
---|---|
278 end, 1); | 278 end, 1); |
279 | 279 |
280 -- publish on unacked smacks message | 280 -- publish on unacked smacks message |
281 local function process_smacks_stanza(stanza, session) | 281 local function process_smacks_stanza(stanza, session) |
282 if session.push_identifier then | 282 if session.push_identifier then |
283 session.log("debug", "Invoking cloud handle_notify_request for smacks queued stanza"); | 283 session.log("debug", "Invoking cloud handle_notify_request() for smacks queued stanza"); |
284 local user_push_services = {[session.push_identifier] = session.push_settings}; | 284 local user_push_services = {[session.push_identifier] = session.push_settings}; |
285 local node = get_push_settings(stanza, session); | 285 local node = get_push_settings(stanza, session); |
286 handle_notify_request(stanza, node, user_push_services); | 286 handle_notify_request(stanza, node, user_push_services); |
287 end | 287 end |
288 return stanza; | 288 return stanza; |
289 end | |
290 | |
291 local function process_smacks_queue(queue, session) | |
292 if not session.push_identifier then return; end | |
293 local user_push_services = {[session.push_identifier] = session.push_settings}; | |
294 for i=1, #queue do | |
295 local stanza = queue[i]; | |
296 local node = get_push_settings(stanza, session); | |
297 session.log("debug", "Invoking cloud handle_notify_request() for smacks queued stanza: %d", i); | |
298 if handle_notify_request(stanza, node, user_push_services) ~= 0 then | |
299 session.log("debug", "Cloud handle_notify_request() > 0, not notifying for other queued stanzas"); | |
300 return; -- only notify for one stanza in the queue, not for all in a row | |
301 end | |
302 end | |
289 end | 303 end |
290 | 304 |
291 -- smacks hibernation is started | 305 -- smacks hibernation is started |
292 local function hibernate_session(event) | 306 local function hibernate_session(event) |
293 local session = event.origin; | 307 local session = event.origin; |
294 local queue = event.queue; | 308 local queue = event.queue; |
295 -- process unacked stanzas | 309 -- process unacked stanzas |
296 for i=1,#queue do | 310 process_smacks_queue(queue, session); |
297 process_smacks_stanza(queue[i], session); | |
298 end | |
299 -- process future unacked (hibernated) stanzas | 311 -- process future unacked (hibernated) stanzas |
300 filters.add_filter(session, "stanzas/out", process_smacks_stanza); | 312 filters.add_filter(session, "stanzas/out", process_smacks_stanza); |
301 end | 313 end |
302 | 314 |
303 -- smacks hibernation is ended | 315 -- smacks hibernation is ended |
316 -- smacks ack is delayed | 328 -- smacks ack is delayed |
317 local function ack_delayed(event) | 329 local function ack_delayed(event) |
318 local session = event.origin; | 330 local session = event.origin; |
319 local queue = event.queue; | 331 local queue = event.queue; |
320 -- process unacked stanzas (handle_notify_request() will only send push requests for new stanzas) | 332 -- process unacked stanzas (handle_notify_request() will only send push requests for new stanzas) |
321 for i=1,#queue do | 333 process_smacks_queue(queue, session); |
322 process_smacks_stanza(queue[i], session); | |
323 end | |
324 end | 334 end |
325 | 335 |
326 -- archive message added | 336 -- archive message added |
327 local function archive_message_added(event) | 337 local function archive_message_added(event) |
328 -- event is: { origin = origin, stanza = stanza, for_user = store_user, id = id } | 338 -- event is: { origin = origin, stanza = stanza, for_user = store_user, id = id } |
348 identifier_found = session; | 358 identifier_found = session; |
349 break; | 359 break; |
350 end | 360 end |
351 end | 361 end |
352 if identifier_found then | 362 if identifier_found then |
353 identifier_found.log("debug", "Not notifying '%s' of new MAM stanza (session still alive)", identifier); | 363 identifier_found.log("debug", "Not cloud notifying '%s' of new MAM stanza (session still alive)", identifier); |
354 else | 364 else |
355 notify_push_sevices[identifier] = push_info; | 365 notify_push_sevices[identifier] = push_info; |
356 end | 366 end |
357 end | 367 end |
358 | 368 |