From 16ae290d9b05778ef470adabb5fd72a8c36ad2c0 Mon Sep 17 00:00:00 2001 From: lazedo Date: Thu, 22 Jun 2017 18:23:34 +0100 Subject: [PATCH 1/2] KAZOO-5581 add unique subscribers --- kamailio/nodes-role.cfg | 9 +++++++-- kamailio/presence-role.cfg | 13 +++++++++++++ 2 files changed, 20 insertions(+), 2 deletions(-) diff --git a/kamailio/nodes-role.cfg b/kamailio/nodes-role.cfg index 04c88a2..534a073 100644 --- a/kamailio/nodes-role.cfg +++ b/kamailio/nodes-role.cfg @@ -45,13 +45,18 @@ route[NODES_ADVERTISE_ROUTE] #!ifdef PRESENCE_ROLE route(COUNT_ALL_SUBSCRIBERS); $var(Subscriptions) = $_s("Subscriptions" : {"message-summary" : $xavp(watchers=>message-summary), "dialog" : $xavp(watchers=>dialog), "presence" : $xavp(watchers=>presence)}); + route(COUNT_ALL_PRESENTITIES); $var(Presentities) = $_s("Presentities" : {"message-summary" : $xavp(watchers=>message-summary), "dialog" : $xavp(watchers=>dialog), "presence" : $xavp(watchers=>presence)}); - $var(Presence) = $_s("Presence" : {$var(Subscriptions), $var(Presentities)}); + + route(COUNT_UNIQUE_SUBSCRIBERS); + $var(Subscribers) = $_s("Subscribers" : {"message-summary" : $xavp(watchers=>message-summary), "dialog" : $xavp(watchers=>dialog), "presence" : $xavp(watchers=>presence)}); + + $var(Presence) = $_s("Presence" : {$var(Subscribers), $var(Subscriptions), $var(Presentities)}); #!else $var(Presence) = ""; #!endif - + $var(Roles) = $_s("Roles" : {$var(Dispatcher), $var(Presence) , $var(Registrar)}); $var(Payload) = '{"Event-Category" : "nodes", "Event-Name" : "advertise", "Expires" : 5000, "Used-Memory" : $(stat(real_used_size){s.int}), "Startup" : $Tb, "XWhApps" : {"kamailio" : {"Startup" : $Tb }}, $var(Roles)}'; kazoo_publish("nodes", "", $var(Payload)); diff --git a/kamailio/presence-role.cfg b/kamailio/presence-role.cfg index c928021..08705c9 100644 --- a/kamailio/presence-role.cfg +++ b/kamailio/presence-role.cfg @@ -235,6 +235,19 @@ route[COUNT_SUBSCRIBERS] xavp_params_explode($var(p), "watchers"); } +route[COUNT_UNIQUE_SUBSCRIBERS] +{ + $var(Query) = $_s(select event, (select count(distinct watcher_username || "@" || watcher_domain) from active_watchers b where b.event = a.event) count from event_list a); + $var(p) = "uri=none"; + if (sql_xquery("cb", "$var(Query)", "subs") == 1) + { + while($xavp(subs) != $null) { + $var(p) = $var(p) + ";" + $xavp(subs=>event) + "=" + $xavp(subs=>count); + pv_unset("$xavp(subs)"); + } + } + xavp_params_explode($var(p), "watchers"); +} event_route[kazoo:consumer-event-presence-dialog-update] { From c004c566c8a480ef5ade788c5e6d0d13bfa51be8 Mon Sep 17 00:00:00 2001 From: lazedo Date: Thu, 22 Jun 2017 18:48:35 +0100 Subject: [PATCH 2/2] KAZOO-5581 optimize queries --- kamailio/nodes-role.cfg | 4 +--- kamailio/presence-role.cfg | 19 +++---------------- 2 files changed, 4 insertions(+), 19 deletions(-) diff --git a/kamailio/nodes-role.cfg b/kamailio/nodes-role.cfg index 534a073..7fb20a7 100644 --- a/kamailio/nodes-role.cfg +++ b/kamailio/nodes-role.cfg @@ -45,13 +45,11 @@ route[NODES_ADVERTISE_ROUTE] #!ifdef PRESENCE_ROLE route(COUNT_ALL_SUBSCRIBERS); $var(Subscriptions) = $_s("Subscriptions" : {"message-summary" : $xavp(watchers=>message-summary), "dialog" : $xavp(watchers=>dialog), "presence" : $xavp(watchers=>presence)}); + $var(Subscribers) = $_s("Subscribers" : {"message-summary" : $xavp(watchers=>message-summary_unique), "dialog" : $xavp(watchers=>dialog_unique), "presence" : $xavp(watchers=>presence_unique)}); route(COUNT_ALL_PRESENTITIES); $var(Presentities) = $_s("Presentities" : {"message-summary" : $xavp(watchers=>message-summary), "dialog" : $xavp(watchers=>dialog), "presence" : $xavp(watchers=>presence)}); - route(COUNT_UNIQUE_SUBSCRIBERS); - $var(Subscribers) = $_s("Subscribers" : {"message-summary" : $xavp(watchers=>message-summary), "dialog" : $xavp(watchers=>dialog), "presence" : $xavp(watchers=>presence)}); - $var(Presence) = $_s("Presence" : {$var(Subscribers), $var(Subscriptions), $var(Presentities)}); #!else $var(Presence) = ""; diff --git a/kamailio/presence-role.cfg b/kamailio/presence-role.cfg index 08705c9..471d1e9 100644 --- a/kamailio/presence-role.cfg +++ b/kamailio/presence-role.cfg @@ -209,12 +209,13 @@ route[COUNT_ALL_PRESENTITIES] route[COUNT_ALL_SUBSCRIBERS] { - $var(Query) = $_s(select event, (select count(*) from active_watchers b where b.event = a.event) count from event_list a); - $var(p) = $_s(uri=$var(presentity)); + $var(Query) = $_s(select a.event, count(distinct watcher_username || "@" || watcher_domain) count_unique, count(*) count from event_list a, active_watchers b where b.event = a.event group by a.event); + $var(p) = "uri=none"; if (sql_xquery("cb", "$var(Query)", "subs") == 1) { while($xavp(subs) != $null) { $var(p) = $var(p) + ";" + $xavp(subs=>event) + "=" + $xavp(subs=>count); + $var(p) = $var(p) + ";" + $xavp(subs=>event) + "_unique=" + $xavp(subs=>count_unique); pv_unset("$xavp(subs)"); } } @@ -235,20 +236,6 @@ route[COUNT_SUBSCRIBERS] xavp_params_explode($var(p), "watchers"); } -route[COUNT_UNIQUE_SUBSCRIBERS] -{ - $var(Query) = $_s(select event, (select count(distinct watcher_username || "@" || watcher_domain) from active_watchers b where b.event = a.event) count from event_list a); - $var(p) = "uri=none"; - if (sql_xquery("cb", "$var(Query)", "subs") == 1) - { - while($xavp(subs) != $null) { - $var(p) = $var(p) + ";" + $xavp(subs=>event) + "=" + $xavp(subs=>count); - pv_unset("$xavp(subs)"); - } - } - xavp_params_explode($var(p), "watchers"); -} - event_route[kazoo:consumer-event-presence-dialog-update] { $var(Now) = $TS;