aboutsummaryrefslogtreecommitdiffstats
path: root/src
diff options
context:
space:
mode:
authorVsevolod Stakhov <vsevolod@highsecure.ru>2014-12-20 23:17:35 +0000
committerVsevolod Stakhov <vsevolod@highsecure.ru>2014-12-20 23:17:35 +0000
commit2b694310d35547383f5525805b57cf9cb06cddba (patch)
treeb46c01e951c23a79622b1203a4b1318197d4bdb6 /src
parenta8ad16bcc7a9591251383a719ffd71b428077e6e (diff)
downloadrspamd-2b694310d35547383f5525805b57cf9cb06cddba.tar.gz
rspamd-2b694310d35547383f5525805b57cf9cb06cddba.zip
Implement shingles insertions.
Diffstat (limited to 'src')
-rw-r--r--src/libserver/fuzzy_backend.c22
1 files changed, 17 insertions, 5 deletions
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);
+ }
+ }
}
}