Delete expired SMS automatically.
Delete expired SMS whenever we are done processing an SMS-related signal. In order to minimize additional latency only one SMS is removed at a time. Change-Id: I56cbe716e52b679c4b94f6cbb4a171306975be2e Related: OS#2354
This commit is contained in:
parent
1e67fea7ba
commit
14e051776f
|
@ -51,6 +51,7 @@ int db_sms_inc_deliver_attempts(struct gsm_sms *sms);
|
|||
int db_sms_delete_by_msisdn(const char *msisdn);
|
||||
int db_sms_delete_sent_message_by_id(unsigned long long sms_id);
|
||||
int db_sms_delete_expired_message_by_id(unsigned long long sms_id);
|
||||
void db_sms_delete_oldest_expired_message(void);
|
||||
|
||||
/* Statistics counter storage */
|
||||
struct osmo_counter;
|
||||
|
|
|
@ -989,22 +989,11 @@ int db_sms_delete_sent_message_by_id(unsigned long long sms_id)
|
|||
return 0;
|
||||
}
|
||||
|
||||
int db_sms_delete_expired_message_by_id(unsigned long long sms_id)
|
||||
|
||||
static int delete_expired_sms(unsigned long long sms_id, time_t created, time_t validity_timestamp)
|
||||
{
|
||||
dbi_result result;
|
||||
time_t created, validity_timestamp, now, min_created;
|
||||
|
||||
result = dbi_conn_queryf(conn, "SELECT created,valid_until FROM SMS WHERE id = %llu", sms_id);
|
||||
if (!result)
|
||||
return -1;
|
||||
if (!next_row(result)) {
|
||||
dbi_result_free(result);
|
||||
return -1;
|
||||
}
|
||||
|
||||
created = dbi_result_get_datetime(result, "created");
|
||||
validity_timestamp = dbi_result_get_datetime(result, "valid_until");
|
||||
dbi_result_free(result);
|
||||
time_t now, min_created;
|
||||
|
||||
now = time(NULL);
|
||||
if (validity_timestamp > now)
|
||||
|
@ -1026,6 +1015,47 @@ int db_sms_delete_expired_message_by_id(unsigned long long sms_id)
|
|||
return 0;
|
||||
}
|
||||
|
||||
int db_sms_delete_expired_message_by_id(unsigned long long sms_id)
|
||||
{
|
||||
dbi_result result;
|
||||
time_t created, validity_timestamp;
|
||||
|
||||
result = dbi_conn_queryf(conn, "SELECT created,valid_until FROM SMS WHERE id = %llu", sms_id);
|
||||
if (!result)
|
||||
return -1;
|
||||
if (!next_row(result)) {
|
||||
dbi_result_free(result);
|
||||
return -1;
|
||||
}
|
||||
|
||||
created = dbi_result_get_datetime(result, "created");
|
||||
validity_timestamp = dbi_result_get_datetime(result, "valid_until");
|
||||
|
||||
dbi_result_free(result);
|
||||
return delete_expired_sms(sms_id, created, validity_timestamp);
|
||||
}
|
||||
|
||||
void db_sms_delete_oldest_expired_message(void)
|
||||
{
|
||||
dbi_result result;
|
||||
|
||||
result = dbi_conn_queryf(conn, "SELECT id,created,valid_until FROM SMS ORDER BY created LIMIT 1");
|
||||
if (!result)
|
||||
return;
|
||||
|
||||
if (next_row(result)) {
|
||||
unsigned long long sms_id;
|
||||
time_t created, validity_timestamp;
|
||||
|
||||
sms_id = dbi_result_get_ulonglong(result, "id");
|
||||
created = dbi_result_get_datetime(result, "created");
|
||||
validity_timestamp = dbi_result_get_datetime(result, "valid_until");
|
||||
delete_expired_sms(sms_id, created, validity_timestamp);
|
||||
}
|
||||
|
||||
dbi_result_free(result);
|
||||
}
|
||||
|
||||
int db_store_counter(struct osmo_counter *ctr)
|
||||
{
|
||||
dbi_result result;
|
||||
|
|
|
@ -529,6 +529,9 @@ static int sms_sms_cb(unsigned int subsys, unsigned int signal,
|
|||
sig_sms->paging_result);
|
||||
}
|
||||
|
||||
/* While here, attempt to remove an expired SMS from the DB. */
|
||||
db_sms_delete_oldest_expired_message();
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
|
|
Loading…
Reference in New Issue