Skip to content

Commit

Permalink
Removed useless SQL condition
Browse files Browse the repository at this point in the history
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)
  • Loading branch information
bogdan-iancu committed Nov 18, 2019
1 parent b87bad8 commit 312cad8
Showing 1 changed file with 10 additions and 36 deletions.
46 changes: 10 additions & 36 deletions modules/usrloc/ucontact.c
Expand Up @@ -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;
Expand Down Expand Up @@ -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");
Expand All @@ -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;
}
Expand All @@ -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;
Expand All @@ -856,25 +841,14 @@ 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;
}

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;
}
Expand Down

0 comments on commit 312cad8

Please sign in to comment.