summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorVsevolod Stakhov <vsevolod@highsecure.ru>2019-03-29 17:49:32 +0000
committerVsevolod Stakhov <vsevolod@highsecure.ru>2019-03-29 17:49:32 +0000
commit9269c1d0c60d52ab1885ada800f88d3dc9dbc5f1 (patch)
tree3e73148159f9190e4e3fa2d71c27492b0cc0aca4
parent2381d38cb1f7afdfb504870a03c259ba71983902 (diff)
downloadrspamd-9269c1d0c60d52ab1885ada800f88d3dc9dbc5f1.tar.gz
rspamd-9269c1d0c60d52ab1885ada800f88d3dc9dbc5f1.zip
[Minor] Fix learns count in sqlite3 backend
Issue: #2251 Contributed by: @beiDei8z
-rw-r--r--src/libstat/backends/sqlite3_backend.c56
1 files changed, 40 insertions, 16 deletions
diff --git a/src/libstat/backends/sqlite3_backend.c b/src/libstat/backends/sqlite3_backend.c
index 78c22f7de..8a3dcdc0c 100644
--- a/src/libstat/backends/sqlite3_backend.c
+++ b/src/libstat/backends/sqlite3_backend.c
@@ -84,8 +84,10 @@ enum rspamd_stat_sqlite3_stmt_idx {
RSPAMD_STAT_BACKEND_TRANSACTION_ROLLBACK,
RSPAMD_STAT_BACKEND_GET_TOKEN,
RSPAMD_STAT_BACKEND_SET_TOKEN,
- RSPAMD_STAT_BACKEND_INC_LEARNS,
- RSPAMD_STAT_BACKEND_DEC_LEARNS,
+ RSPAMD_STAT_BACKEND_INC_LEARNS_LANG,
+ RSPAMD_STAT_BACKEND_INC_LEARNS_USER,
+ RSPAMD_STAT_BACKEND_DEC_LEARNS_LANG,
+ RSPAMD_STAT_BACKEND_DEC_LEARNS_USER,
RSPAMD_STAT_BACKEND_GET_LEARNS,
RSPAMD_STAT_BACKEND_GET_LANGUAGE,
RSPAMD_STAT_BACKEND_GET_USER,
@@ -169,22 +171,38 @@ static struct rspamd_sqlite3_prstmt prepared_stmts[RSPAMD_STAT_BACKEND_MAX] =
.flags = 0,
.ret = ""
},
- [RSPAMD_STAT_BACKEND_INC_LEARNS] = {
- .idx = RSPAMD_STAT_BACKEND_INC_LEARNS,
- .sql = "UPDATE languages SET learns=learns + 1 WHERE id=?1;"
- "UPDATE users SET learns=learns + 1 WHERE id=?2;",
+ [RSPAMD_STAT_BACKEND_INC_LEARNS_LANG] = {
+ .idx = RSPAMD_STAT_BACKEND_INC_LEARNS_LANG,
+ .sql = "UPDATE languages SET learns=learns + 1 WHERE id=?1;",
.stmt = NULL,
- .args = "II",
+ .args = "I",
.result = SQLITE_DONE,
.flags = 0,
.ret = ""
},
- [RSPAMD_STAT_BACKEND_DEC_LEARNS] = {
- .idx = RSPAMD_STAT_BACKEND_DEC_LEARNS,
- .sql = "UPDATE languages SET learns=MAX(0, learns - 1) WHERE id=?1;"
- "UPDATE users SET learns=MAX(0, learns - 1) WHERE id=?2;",
+ [RSPAMD_STAT_BACKEND_INC_LEARNS_USER] = {
+ .idx = RSPAMD_STAT_BACKEND_INC_LEARNS_USER,
+ .sql = "UPDATE users SET learns=learns + 1 WHERE id=?1;",
.stmt = NULL,
- .args = "II",
+ .args = "I",
+ .result = SQLITE_DONE,
+ .flags = 0,
+ .ret = ""
+ },
+ [RSPAMD_STAT_BACKEND_DEC_LEARNS_LANG] = {
+ .idx = RSPAMD_STAT_BACKEND_DEC_LEARNS_LANG,
+ .sql = "UPDATE languages SET learns=MAX(0, learns - 1) WHERE id=?1;",
+ .stmt = NULL,
+ .args = "I",
+ .result = SQLITE_DONE,
+ .flags = 0,
+ .ret = ""
+ },
+ [RSPAMD_STAT_BACKEND_DEC_LEARNS_USER] = {
+ .idx = RSPAMD_STAT_BACKEND_DEC_LEARNS_USER,
+ .sql = "UPDATE users SET learns=MAX(0, learns - 1) WHERE id=?1;",
+ .stmt = NULL,
+ .args = "I",
.result = SQLITE_DONE,
.flags = 0,
.ret = ""
@@ -890,8 +908,11 @@ rspamd_sqlite3_inc_learns (struct rspamd_task *task, gpointer runtime,
g_assert (rt != NULL);
bk = rt->db;
rspamd_sqlite3_run_prstmt (task->task_pool, bk->sqlite, bk->prstmt,
- RSPAMD_STAT_BACKEND_INC_LEARNS,
- rt->lang_id, rt->user_id);
+ RSPAMD_STAT_BACKEND_INC_LEARNS_LANG,
+ rt->lang_id);
+ rspamd_sqlite3_run_prstmt (task->task_pool, bk->sqlite, bk->prstmt,
+ RSPAMD_STAT_BACKEND_INC_LEARNS_USER,
+ rt->user_id);
if (bk->in_transaction) {
rspamd_sqlite3_run_prstmt (task->task_pool, bk->sqlite, bk->prstmt,
@@ -916,8 +937,11 @@ rspamd_sqlite3_dec_learns (struct rspamd_task *task, gpointer runtime,
g_assert (rt != NULL);
bk = rt->db;
rspamd_sqlite3_run_prstmt (task->task_pool, bk->sqlite, bk->prstmt,
- RSPAMD_STAT_BACKEND_DEC_LEARNS,
- rt->lang_id, rt->user_id);
+ RSPAMD_STAT_BACKEND_DEC_LEARNS_LANG,
+ rt->lang_id);
+ rspamd_sqlite3_run_prstmt (task->task_pool, bk->sqlite, bk->prstmt,
+ RSPAMD_STAT_BACKEND_DEC_LEARNS_USER,
+ rt->user_id);
if (bk->in_transaction) {
rspamd_sqlite3_run_prstmt (task->task_pool, bk->sqlite, bk->prstmt,