From: Vsevolod Stakhov Date: Tue, 17 Nov 2015 17:03:13 +0000 (+0000) Subject: Properly return count of hashes for multiple fuzzy storages X-Git-Tag: 1.1.0~538 X-Git-Url: https://source.dussan.org/?a=commitdiff_plain;h=3cfbb45a4a84836e118992099cea233920b6f92e;p=rspamd.git Properly return count of hashes for multiple fuzzy storages --- diff --git a/src/libserver/fuzzy_backend.c b/src/libserver/fuzzy_backend.c index 696c9487b..56ea187cc 100644 --- a/src/libserver/fuzzy_backend.c +++ b/src/libserver/fuzzy_backend.c @@ -628,8 +628,6 @@ rspamd_fuzzy_backend_add (struct rspamd_fuzzy_backend *backend, (gint64) time (NULL)); if (rc == SQLITE_OK) { - backend->count++; - if (cmd->shingles_count > 0) { id = sqlite3_last_insert_rowid (backend->db); shcmd = (const struct rspamd_fuzzy_shingle_cmd *) cmd; @@ -681,8 +679,6 @@ rspamd_fuzzy_backend_del (struct rspamd_fuzzy_backend *backend, RSPAMD_FUZZY_BACKEND_DELETE, cmd->digest); - backend->count -= sqlite3_changes (backend->db); - rspamd_fuzzy_backend_cleanup_stmt (backend, RSPAMD_FUZZY_BACKEND_DELETE); @@ -863,7 +859,19 @@ rspamd_fuzzy_backend_close (struct rspamd_fuzzy_backend *backend) gsize rspamd_fuzzy_backend_count (struct rspamd_fuzzy_backend *backend) { - return backend != NULL ? backend->count : 0; + if (backend) { + if (rspamd_fuzzy_backend_run_stmt (backend, RSPAMD_FUZZY_BACKEND_COUNT) + == SQLITE_OK) { + backend->count = sqlite3_column_int64 ( + prepared_stmts[RSPAMD_FUZZY_BACKEND_COUNT].stmt, 0); + } + + rspamd_fuzzy_backend_cleanup_stmt (backend, RSPAMD_FUZZY_BACKEND_COUNT); + + return backend->count; + } + + return 0; } gsize