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



gint gint
rspamd_stat_cache_sqlite3_check (struct rspamd_task *task, 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 rspamd_stat_sqlite3_ctx *ctx = (struct rspamd_stat_sqlite3_ctx *)c;
struct mime_text_part *part; struct mime_text_part *part;


gint gint
rspamd_stat_cache_sqlite3_learn (struct rspamd_task *task, 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; struct rspamd_stat_sqlite3_ctx *ctx = (struct rspamd_stat_sqlite3_ctx *)c;
gboolean unlearn = !!(task->flags & RSPAMD_TASK_FLAG_UNLEARN); gboolean unlearn = !!(task->flags & RSPAMD_TASK_FLAG_UNLEARN);

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

msg_debug_config ("added backend %s for symbol %s", msg_debug_config ("added backend %s for symbol %s",
bk->name, stf->symbol); 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) { if (st->bkcf == NULL) {
msg_err_config ("cannot init backend %s for statfile %s", msg_err_config ("cannot init backend %s for statfile %s",

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

struct rspamd_classifier { struct rspamd_classifier {
struct rspamd_stat_ctx *ctx; struct rspamd_stat_ctx *ctx;
GArray *statfiles_ids; GArray *statfiles_ids;
struct rspamd_stat_cache *cache;
gpointer cachecf;
gulong spam_learns; gulong spam_learns;
gulong ham_learns; gulong ham_learns;
struct rspamd_classifier_config *cfg; struct rspamd_classifier_config *cfg;
struct rspamd_statfile_config *stcf; struct rspamd_statfile_config *stcf;
struct rspamd_classifier *classifier; struct rspamd_classifier *classifier;
struct rspamd_stat_backend *backend; struct rspamd_stat_backend *backend;
struct rspamd_stat_cache *cache;
gpointer cachecf;
gpointer bkcf; gpointer bkcf;
}; };



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

{ {
rspamd_learn_t learn_res = RSPAMD_LEARN_OK; rspamd_learn_t learn_res = RSPAMD_LEARN_OK;
struct rspamd_classifier *cl; struct rspamd_classifier *cl;
gpointer rt;
guint i; guint i;


/* Check whether we have learned that file */ /* Check whether we have learned that file */
} }


if (cl->cache && cl->cachecf) { 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) { if (learn_res == RSPAMD_LEARN_INGORE) {
{ {
struct rspamd_classifier *cl; struct rspamd_classifier *cl;
struct rspamd_statfile *st; struct rspamd_statfile *st;
gpointer bk_run;
gpointer bk_run, cache_run;
guint i, j; guint i, j;
gint id; gint id;
gboolean res = TRUE; gboolean res = TRUE;
continue; 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 ++) { for (j = 0; j < cl->statfiles_ids->len; j ++) {
id = g_array_index (cl->statfiles_ids, gint, j); id = g_array_index (cl->statfiles_ids, gint, j);
st = g_ptr_array_index (st_ctx->statfiles, id); st = g_ptr_array_index (st_ctx->statfiles, id);

Loading…
Cancel
Save