mirror of
https://github.com/eclipse-mosquitto/mosquitto.git
synced 2026-09-24 09:14:02 +08:00
Optimise persist client msg clearing.
This commit is contained in:
@@ -119,19 +119,32 @@ int persist_sqlite__client_msg_clear_cb(int event, void *event_data, void *userd
|
||||
|
||||
UNUSED(event);
|
||||
|
||||
if(sqlite3_bind_text(ms->client_msg_clear_stmt, 1, ed->client_id, (int)strlen(ed->client_id), SQLITE_STATIC) == SQLITE_OK
|
||||
&& sqlite3_bind_int64(ms->client_msg_clear_stmt, 2, ed->direction) == SQLITE_OK
|
||||
){
|
||||
|
||||
ms->event_count++;
|
||||
rc = sqlite3_step(ms->client_msg_clear_stmt);
|
||||
if(rc == SQLITE_DONE){
|
||||
rc = MOSQ_ERR_SUCCESS;
|
||||
}else{
|
||||
rc = MOSQ_ERR_UNKNOWN;
|
||||
if(ed->direction == mosq_bmd_all){
|
||||
if(sqlite3_bind_text(ms->client_msg_clear_all_stmt, 1, ed->client_id, (int)strlen(ed->client_id), SQLITE_STATIC) == SQLITE_OK){
|
||||
ms->event_count++;
|
||||
rc = sqlite3_step(ms->client_msg_clear_all_stmt);
|
||||
if(rc == SQLITE_DONE){
|
||||
rc = MOSQ_ERR_SUCCESS;
|
||||
}else{
|
||||
rc = MOSQ_ERR_UNKNOWN;
|
||||
}
|
||||
}
|
||||
sqlite3_reset(ms->client_msg_clear_all_stmt);
|
||||
}else{
|
||||
if(sqlite3_bind_text(ms->client_msg_clear_stmt, 1, ed->client_id, (int)strlen(ed->client_id), SQLITE_STATIC) == SQLITE_OK
|
||||
&& sqlite3_bind_int64(ms->client_msg_clear_stmt, 2, ed->direction) == SQLITE_OK
|
||||
){
|
||||
|
||||
ms->event_count++;
|
||||
rc = sqlite3_step(ms->client_msg_clear_stmt);
|
||||
if(rc == SQLITE_DONE){
|
||||
rc = MOSQ_ERR_SUCCESS;
|
||||
}else{
|
||||
rc = MOSQ_ERR_UNKNOWN;
|
||||
}
|
||||
}
|
||||
sqlite3_reset(ms->client_msg_clear_stmt);
|
||||
}
|
||||
sqlite3_reset(ms->client_msg_clear_stmt);
|
||||
|
||||
return rc;
|
||||
}
|
||||
|
||||
@@ -203,6 +203,12 @@ static int prepare_statements(struct mosquitto_sqlite *ms)
|
||||
&ms->client_msg_clear_stmt, NULL);
|
||||
if(rc) goto fail;
|
||||
|
||||
rc = sqlite3_prepare_v3(ms->db,
|
||||
"DELETE FROM client_msgs WHERE client_id=?",
|
||||
-1, SQLITE_PREPARE_PERSISTENT,
|
||||
&ms->client_msg_clear_all_stmt, NULL);
|
||||
if(rc) goto fail;
|
||||
|
||||
/* Message store */
|
||||
rc = sqlite3_prepare_v3(ms->db,
|
||||
"INSERT INTO base_msgs "
|
||||
@@ -297,6 +303,7 @@ void persist_sqlite__cleanup(struct mosquitto_sqlite *ms)
|
||||
sqlite3_finalize(ms->client_msg_remove_stmt);
|
||||
sqlite3_finalize(ms->client_msg_update_stmt);
|
||||
sqlite3_finalize(ms->client_msg_clear_stmt);
|
||||
sqlite3_finalize(ms->client_msg_clear_all_stmt);
|
||||
sqlite3_finalize(ms->base_msg_add_stmt);
|
||||
sqlite3_finalize(ms->base_msg_remove_stmt);
|
||||
sqlite3_finalize(ms->base_msg_load_stmt);
|
||||
|
||||
@@ -39,6 +39,7 @@ struct mosquitto_sqlite {
|
||||
sqlite3_stmt *client_msg_remove_stmt;
|
||||
sqlite3_stmt *client_msg_update_stmt;
|
||||
sqlite3_stmt *client_msg_clear_stmt;
|
||||
sqlite3_stmt *client_msg_clear_all_stmt;
|
||||
sqlite3_stmt *base_msg_add_stmt;
|
||||
sqlite3_stmt *base_msg_remove_stmt;
|
||||
sqlite3_stmt *base_msg_load_stmt;
|
||||
|
||||
Reference in New Issue
Block a user