Skip to content

Commit

Permalink
When updating the database records, first perform all update and inse…
Browse files Browse the repository at this point in the history
…rts and then check the timeout for expired records -> records to be deleted.

Doing first the delete may hide records "expired but to be updated".
Credits go to Nick Altmann
Closes bug #112.
  • Loading branch information
bogdan-iancu committed Mar 10, 2014
1 parent ec56716 commit 3c1164a
Showing 1 changed file with 17 additions and 16 deletions.
33 changes: 17 additions & 16 deletions modules/presence/subscribe.c
Expand Up @@ -1471,26 +1471,11 @@ void update_db_subs(db_con_t *db,db_func_t dbf, shtable_t hash_table,
update_vals[u_version_col].nul = 0;
n_update_cols++;

if(db== NULL)
{
if (db==NULL){
LM_ERR("null database connection\n");
return;
}

LM_DBG("delete expired\n");
update_vals[0].val.int_val= (int)time(NULL);
update_ops[0]= OP_LT;
CON_PS_REFERENCE(db) = &my_ps_delete;
if(dbf.use_table(db, &active_watchers_table) < 0)
{
LM_ERR("deleting expired information from database\n");
}

if(dbf.delete(db, update_cols, update_ops, update_vals, 1) < 0)
{
LM_ERR("deleting expired information from database\n");
}

for(i=0; i<htable_size; i++)
{
if(!no_lock)
Expand Down Expand Up @@ -1610,8 +1595,24 @@ void update_db_subs(db_con_t *db,db_func_t dbf, shtable_t hash_table,
if(!no_lock)
lock_release(&hash_table[i].lock);
}

/* now that all records were updated, delete whatever
was still left as expired */
LM_DBG("delete expired\n");
update_vals[0].val.int_val = (int)time(NULL);
update_ops[0] = OP_LT;
CON_PS_REFERENCE(db) = &my_ps_delete;
if (dbf.use_table(db, &active_watchers_table) < 0) {
LM_ERR("deleting expired information from database\n");
} else {
if (dbf.delete(db, update_cols, update_ops, update_vals, 1) < 0)
LM_ERR("deleting expired information from database\n");
}

return;
}


int insert_subs_db(subs_t* s)
{
static db_ps_t my_ps = NULL;
Expand Down

0 comments on commit 3c1164a

Please sign in to comment.