Delete SMS from the database once they were sent successfully

Currently the SMS database keeps accumulating entries for each SMS.
These entries are never deleted automatically. With this change, we
start deleting SMS which have successfully been sent to subscriber B.

Change-Id: I3749855fe25d9d4e37ec96b0c2bffbc692b66a78
This commit is contained in:
Stefan Sperling 2018-01-18 18:55:26 +01:00
parent 832046d383
commit 6ba2d5a9f7
3 changed files with 18 additions and 0 deletions

View File

@ -49,6 +49,7 @@ struct gsm_sms *db_sms_get_unsent_for_subscr(struct vlr_subscr *vsub,
int db_sms_mark_delivered(struct gsm_sms *sms);
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);
/* Statistics counter storage */
struct osmo_counter;

View File

@ -970,6 +970,22 @@ int db_sms_delete_by_msisdn(const char *msisdn)
return 0;
}
int db_sms_delete_sent_message_by_id(unsigned long long sms_id)
{
dbi_result result;
result = dbi_conn_queryf(conn,
"DELETE FROM SMS WHERE id = %llu AND sent is NOT NULL",
sms_id);
if (!result) {
LOGP(DDB, LOGL_ERROR, "Failed to delete SMS %llu.\n", sms_id);
return 1;
}
dbi_result_free(result);
return 0;
}
int db_store_counter(struct osmo_counter *ctr)
{
dbi_result result;

View File

@ -483,6 +483,7 @@ static int sms_sms_cb(unsigned int subsys, unsigned int signal,
network->sms_queue->pending -= 1;
vsub = vlr_subscr_get(pending->vsub);
sms_pending_free(pending);
db_sms_delete_sent_message_by_id(pending->sms_id);
/* Attempt to send another SMS to this subscriber */
sms_send_next(vsub);
vlr_subscr_put(vsub);