diff options
author | Vsevolod Stakhov <vsevolod@highsecure.ru> | 2016-01-27 14:06:17 +0000 |
---|---|---|
committer | Vsevolod Stakhov <vsevolod@highsecure.ru> | 2016-01-27 14:06:17 +0000 |
commit | 70b43ec9b9ee5743166e705612936b9a1b376708 (patch) | |
tree | df054bf86201561ab7d132a8e0207c452ecf03cf | |
parent | e89b4ef3b35596ec4862ae4c9bb6995e51073ec5 (diff) | |
download | rspamd-70b43ec9b9ee5743166e705612936b9a1b376708.tar.gz rspamd-70b43ec9b9ee5743166e705612936b9a1b376708.zip |
Never set negative learn counts
Issue: #496
-rw-r--r-- | src/libstat/backends/sqlite3_backend.c | 6 |
1 files changed, 3 insertions, 3 deletions
diff --git a/src/libstat/backends/sqlite3_backend.c b/src/libstat/backends/sqlite3_backend.c index 7f57636e4..bead2cecb 100644 --- a/src/libstat/backends/sqlite3_backend.c +++ b/src/libstat/backends/sqlite3_backend.c @@ -190,8 +190,8 @@ static struct rspamd_sqlite3_prstmt prepared_stmts[RSPAMD_STAT_BACKEND_MAX] = }, [RSPAMD_STAT_BACKEND_DEC_LEARNS] = { .idx = RSPAMD_STAT_BACKEND_DEC_LEARNS, - .sql = "UPDATE languages SET learns=learns - 1 WHERE id=?1;" - "UPDATE users SET learns=learns - 1 WHERE id=?2;", + .sql = "UPDATE languages SET learns=MAX(0, learns - 1) WHERE id=?1;" + "UPDATE users SET learns=MAX(0, learns - 1) WHERE id=?2;", .stmt = NULL, .args = "II", .result = SQLITE_DONE, @@ -200,7 +200,7 @@ static struct rspamd_sqlite3_prstmt prepared_stmts[RSPAMD_STAT_BACKEND_MAX] = }, [RSPAMD_STAT_BACKEND_GET_LEARNS] = { .idx = RSPAMD_STAT_BACKEND_GET_LEARNS, - .sql = "SELECT sum(learns) FROM languages;", + .sql = "SELECT SUM(MAX(0, learns)) FROM languages;", .stmt = NULL, .args = "", .result = SQLITE_ROW, |