Browse Source

Fix processing of caches

tags/1.1.0
Vsevolod Stakhov 8 years ago
parent
commit
dd1af5b84e

+ 6
- 2
src/libstat/learn_cache/sqlite3_cache.c View File

@@ -179,7 +179,9 @@ rspamd_stat_cache_sqlite3_runtime (struct rspamd_task *task,

gint
rspamd_stat_cache_sqlite3_check (struct rspamd_task *task,
gboolean is_spam, gpointer c)
gboolean is_spam,
gpointer runtime,
gpointer c)
{
struct rspamd_stat_sqlite3_ctx *ctx = (struct rspamd_stat_sqlite3_ctx *)c;
struct mime_text_part *part;
@@ -240,7 +242,9 @@ rspamd_stat_cache_sqlite3_check (struct rspamd_task *task,

gint
rspamd_stat_cache_sqlite3_learn (struct rspamd_task *task,
gboolean is_spam, gpointer c)
gboolean is_spam,
gpointer runtime,
gpointer c)
{
struct rspamd_stat_sqlite3_ctx *ctx = (struct rspamd_stat_sqlite3_ctx *)c;
gboolean unlearn = !!(task->flags & RSPAMD_TASK_FLAG_UNLEARN);

+ 8
- 5
src/libstat/stat_config.c View File

@@ -182,11 +182,14 @@ rspamd_stat_init (struct rspamd_config *cfg, struct event_base *ev_base)
msg_debug_config ("added backend %s for symbol %s",
bk->name, stf->symbol);

st->cache = rspamd_stat_get_cache (cache_name);
g_assert (st->cache != NULL);
st->cachecf = st->cache->init (stat_ctx, cfg, st, cache_obj);
msg_debug_config ("added cache %s for symbol %s",
st->cache->name, stf->symbol);
/* XXX: bad hack to pass statfiles configuration to cache */
if (cl->cache == NULL) {
cl->cache = rspamd_stat_get_cache (cache_name);
g_assert (cl->cache != NULL);
cl->cachecf = cl->cache->init (stat_ctx, cfg, st, cache_obj);
msg_debug_config ("added cache %s for symbol %s",
cl->cache->name, stf->symbol);
}

if (st->bkcf == NULL) {
msg_err_config ("cannot init backend %s for statfile %s",

+ 2
- 2
src/libstat/stat_internal.h View File

@@ -42,6 +42,8 @@ struct rspamd_statfile_runtime {
struct rspamd_classifier {
struct rspamd_stat_ctx *ctx;
GArray *statfiles_ids;
struct rspamd_stat_cache *cache;
gpointer cachecf;
gulong spam_learns;
gulong ham_learns;
struct rspamd_classifier_config *cfg;
@@ -53,8 +55,6 @@ struct rspamd_statfile {
struct rspamd_statfile_config *stcf;
struct rspamd_classifier *classifier;
struct rspamd_stat_backend *backend;
struct rspamd_stat_cache *cache;
gpointer cachecf;
gpointer bkcf;
};


+ 10
- 3
src/libstat/stat_process.c View File

@@ -376,6 +376,7 @@ rspamd_stat_cache_check (struct rspamd_stat_ctx *st_ctx,
{
rspamd_learn_t learn_res = RSPAMD_LEARN_OK;
struct rspamd_classifier *cl;
gpointer rt;
guint i;

/* Check whether we have learned that file */
@@ -389,8 +390,9 @@ rspamd_stat_cache_check (struct rspamd_stat_ctx *st_ctx,
}

if (cl->cache && cl->cachecf) {
learn_res = cl->cache->process (task, spam,
cl->cachecf);
rt = cl->cache->runtime (task, cl->cachecf);
learn_res = cl->cache->check (task, spam,
cl->cachecf, rt);
}

if (learn_res == RSPAMD_LEARN_INGORE) {
@@ -558,7 +560,7 @@ rspamd_stat_backends_post_learn (struct rspamd_stat_ctx *st_ctx,
{
struct rspamd_classifier *cl;
struct rspamd_statfile *st;
gpointer bk_run;
gpointer bk_run, cache_run;
guint i, j;
gint id;
gboolean res = TRUE;
@@ -572,6 +574,11 @@ rspamd_stat_backends_post_learn (struct rspamd_stat_ctx *st_ctx,
continue;
}

if (cl->cache) {
cache_run = cl->cache->runtime (task, cl->cachecf);
cl->cache->learn (task, spam, cache_run, cl->cachecf);
}

for (j = 0; j < cl->statfiles_ids->len; j ++) {
id = g_array_index (cl->statfiles_ids, gint, j);
st = g_ptr_array_index (st_ctx->statfiles, id);

Loading…
Cancel
Save