From 487e1837c1be117de3c6243e8c21e60e2ec76740 Mon Sep 17 00:00:00 2001 From: Anthony Minessale Date: Wed, 13 Nov 2013 21:41:37 +0500 Subject: [PATCH] try to improve performance of subscribe sip handler Conflicts: src/mod/endpoints/mod_sofia/sofia_presence.c --- src/mod/endpoints/mod_sofia/sofia_glue.c | 1 + src/mod/endpoints/mod_sofia/sofia_presence.c | 15 +++++++-------- 2 files changed, 8 insertions(+), 8 deletions(-) diff --git a/src/mod/endpoints/mod_sofia/sofia_glue.c b/src/mod/endpoints/mod_sofia/sofia_glue.c index 92e018acce..68f47600ad 100644 --- a/src/mod/endpoints/mod_sofia/sofia_glue.c +++ b/src/mod/endpoints/mod_sofia/sofia_glue.c @@ -6446,6 +6446,7 @@ int sofia_glue_init_sql(sofia_profile_t *profile) "create index sr_orig_server_host on sip_registrations (orig_server_host)", "create index sr_orig_hostname on sip_registrations (orig_hostname)", "create index ss_call_id on sip_subscriptions (call_id)", + "create index ss_multi on sip_subscriptions (call_id, profile_name, hostname)", "create index ss_hostname on sip_subscriptions (hostname)", "create index ss_network_ip on sip_subscriptions (network_ip)", "create index ss_sip_user on sip_subscriptions (sip_user)", diff --git a/src/mod/endpoints/mod_sofia/sofia_presence.c b/src/mod/endpoints/mod_sofia/sofia_presence.c index a79ebc4989..9259f85c75 100644 --- a/src/mod/endpoints/mod_sofia/sofia_presence.c +++ b/src/mod/endpoints/mod_sofia/sofia_presence.c @@ -3575,8 +3575,7 @@ void sofia_presence_handle_sip_i_subscribe(int status, int found_proto = 0; const char *use_to_tag; char to_tag[13] = ""; - char buf[32] = ""; - int subbed = 0; + char buf[80] = ""; if (!sip) { return; @@ -3706,8 +3705,8 @@ void sofia_presence_handle_sip_i_subscribe(int status, } if ((sub_state != nua_substate_terminated)) { - sql = switch_mprintf("select count(*) from sip_subscriptions where call_id='%q' and hostname='%q' and profile_name='%q'", - call_id, mod_sofia_globals.hostname, profile->name); + sql = switch_mprintf("select call_id from sip_subscriptions where call_id='%q' and profile_name='%q' and hostname='%q'", + call_id, profile->name, mod_sofia_globals.hostname); sofia_glue_execute_sql2str(profile, profile->dbh_mutex, sql, buf, sizeof(buf)); @@ -3718,7 +3717,7 @@ void sofia_presence_handle_sip_i_subscribe(int status, switch_safe_free(sql); - if ((subbed = atoi(buf)) > 0) { + if (!zstr(buf)) { sub_state = nua_substate_active; } } @@ -3729,9 +3728,9 @@ void sofia_presence_handle_sip_i_subscribe(int status, sql = switch_mprintf("update sip_subscriptions " "set expires=%ld " - "where hostname='%q' and profile_name='%q' and call_id='%q' and profile_name='%q'", - (long) switch_epoch_time_now(NULL) + exp_delta, mod_sofia_globals.hostname, profile->name, - call_id, profile->name); + "where call_id='%q' and profile_name='%q' and hostname='%q'", + (long) switch_epoch_time_now(NULL) + exp_delta, + call_id, profile->name, mod_sofia_globals.hostname); if (mod_sofia_globals.debug_presence > 0 || mod_sofia_globals.debug_sla > 0) { switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_ERROR,