From: Vsevolod Stakhov Date: Sat, 20 Dec 2014 23:17:35 +0000 (+0000) Subject: Implement shingles insertions. X-Git-Tag: 0.8.0~49 X-Git-Url: https://source.dussan.org/?a=commitdiff_plain;h=2b694310d35547383f5525805b57cf9cb06cddba;p=rspamd.git Implement shingles insertions. --- diff --git a/src/libserver/fuzzy_backend.c b/src/libserver/fuzzy_backend.c index 0e6505579..f7d7ebc84 100644 --- a/src/libserver/fuzzy_backend.c +++ b/src/libserver/fuzzy_backend.c @@ -129,7 +129,7 @@ static struct rspamd_fuzzy_stmts { }, { .idx = RSPAMD_FUZZY_BACKEND_INSERT_SHINGLE, - .sql = "INSERT INTO shingles(value, number, digest_id) " + .sql = "INSERT OR REPLACE INTO shingles(value, number, digest_id) " "VALUES (?1, ?2, ?3);", .args = "III", .stmt = NULL, @@ -651,7 +651,9 @@ gboolean rspamd_fuzzy_backend_add (struct rspamd_fuzzy_backend *backend, const struct rspamd_fuzzy_cmd *cmd) { - int rc; + int rc, i; + gint64 id; + const struct rspamd_fuzzy_shingle_cmd *shcmd; rc = rspamd_fuzzy_backend_run_stmt (backend, RSPAMD_FUZZY_BACKEND_CHECK, cmd->digest); @@ -665,9 +667,19 @@ rspamd_fuzzy_backend_add (struct rspamd_fuzzy_backend *backend, rc = rspamd_fuzzy_backend_run_stmt (backend, RSPAMD_FUZZY_BACKEND_INSERT, (gint)cmd->flag, cmd->digest, (gint64)cmd->value, (gint64)time (NULL)); - backend->count ++; - if (cmd->shingles_count > 0) { - /* Add corresponding shingles */ + 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; + + for (i = 0; i < RSPAMD_SHINGLE_SIZE; i ++) { + rspamd_fuzzy_backend_run_stmt (backend, + RSPAMD_FUZZY_BACKEND_INSERT_SHINGLE, + shcmd->sgl.hashes[i], i, id); + } + } } }