From 312cad88869c84d98307b800975ba41b5e5b65d5 Mon Sep 17 00:00:00 2001 From: Bogdan-Andrei Iancu Date: Mon, 18 Nov 2019 16:48:36 +0200 Subject: [PATCH] Removed useless SQL condition The contact_id is an unique ID of the contact, so using the callid (as part of the query key) is redundant and useless (probabaly a leftover from the code re-factoring when the contact_id concept was introduced) --- modules/usrloc/ucontact.c | 46 +++++++++------------------------------ 1 file changed, 10 insertions(+), 36 deletions(-) diff --git a/modules/usrloc/ucontact.c b/modules/usrloc/ucontact.c index 89a0dbc71ce..5de7afe942d 100644 --- a/modules/usrloc/ucontact.c +++ b/modules/usrloc/ucontact.c @@ -694,12 +694,10 @@ int db_insert_ucontact(ucontact_t* _c,query_list_t **ins_list, int update) int db_update_ucontact(ucontact_t* _c) { static db_ps_t my_ps = NULL; - db_key_t keys1[2]; - db_val_t vals1[2]; + db_key_t keys1[1]; + db_val_t vals1[1]; db_key_t keys2[15]; db_val_t vals2[15]; - int keys1_no = 1; - int keys2_no; if (_c->flags & FL_MEM) { return 0; @@ -796,23 +794,12 @@ int db_update_ucontact(ucontact_t* _c) } else { vals2[13].val.str_val = _c->attr; } - keys2_no = 14; - - if (matching_mode == CONTACT_CALLID) { - /* callid is part of the matching key */ - keys1[keys1_no] = &callid_col; - vals1[keys1_no].type = DB_STR; - vals1[keys1_no].nul = 0; - vals1[keys1_no].val.str_val = _c->callid; - keys1_no++; - } /* callid is part of the update */ - keys2[keys2_no] = &callid_col; - vals2[keys2_no].type = DB_STR; - vals2[keys2_no].nul = 0; - vals2[keys2_no].val.str_val = _c->callid; - keys2_no++; + keys2[14] = &callid_col; + vals2[14].type = DB_STR; + vals2[14].nul = 0; + vals2[14].val.str_val = _c->callid; if (ul_dbf.use_table(ul_dbh, _c->domain) < 0) { LM_ERR("sql use_table failed\n"); @@ -821,8 +808,7 @@ int db_update_ucontact(ucontact_t* _c) CON_PS_REFERENCE(ul_dbh) = &my_ps; - if (ul_dbf.update(ul_dbh, keys1, 0, vals1, keys2, vals2, - keys1_no, keys2_no) < 0) { + if (ul_dbf.update(ul_dbh, keys1, 0, vals1, keys2, vals2, 1, 15)<0) { LM_ERR("updating database failed\n"); goto out_err; } @@ -843,9 +829,8 @@ int db_update_ucontact(ucontact_t* _c) int db_delete_ucontact(ucontact_t* _c) { static db_ps_t my_ps = NULL; - db_key_t keys[2]; - db_val_t vals[2]; - int n; + db_key_t keys[1]; + db_val_t vals[1]; if (_c->flags & FL_MEM) return 0; @@ -856,17 +841,6 @@ int db_delete_ucontact(ucontact_t* _c) VAL_NULL(vals) = 0; VAL_BIGINT(vals) = (long long)_c->contact_id; - n=1; - - if (matching_mode == CONTACT_CALLID) { - /* callid is part of the matching key */ - keys[n] = &callid_col; - vals[n].type = DB_STR; - vals[n].nul = 0; - vals[n].val.str_val = _c->callid; - n++; - } - if (ul_dbf.use_table(ul_dbh, _c->domain) < 0) { LM_ERR("sql use_table failed\n"); return -1; @@ -874,7 +848,7 @@ int db_delete_ucontact(ucontact_t* _c) CON_PS_REFERENCE(ul_dbh) = &my_ps; - if (ul_dbf.delete(ul_dbh, keys, 0, vals, n) < 0) { + if (ul_dbf.delete(ul_dbh, keys, 0, vals, 1) < 0) { LM_ERR("deleting from database failed\n"); return -1; }