diff options
author | Vsevolod Stakhov <vsevolod@highsecure.ru> | 2015-03-29 22:03:14 +0100 |
---|---|---|
committer | Vsevolod Stakhov <vsevolod@highsecure.ru> | 2015-03-29 22:03:14 +0100 |
commit | 6ebf1e5b3058161fe52c142448bfa497d1628e51 (patch) | |
tree | ec7bd1ffcb4f0d6ac3ebcd077a39106d9c602b71 /src/libutil/expression.c | |
parent | 5e31d656fef5a30d12aa1fc264cdb1216d9c16b7 (diff) | |
download | rspamd-6ebf1e5b3058161fe52c142448bfa497d1628e51.tar.gz rspamd-6ebf1e5b3058161fe52c142448bfa497d1628e51.zip |
Use advanced priorities when planning evaluation.
Diffstat (limited to 'src/libutil/expression.c')
-rw-r--r-- | src/libutil/expression.c | 23 |
1 files changed, 22 insertions, 1 deletions
diff --git a/src/libutil/expression.c b/src/libutil/expression.c index d656db37b..2d52419fa 100644 --- a/src/libutil/expression.c +++ b/src/libutil/expression.c @@ -414,12 +414,29 @@ rspamd_ast_priority_traverse (GNode *node, gpointer d) return FALSE; } +#define ATOM_PRIORITY(a) ((a)->p.atom->hits / ((a)->p.atom->avg_ticks > 0 ? \ + (a)->p.atom->avg_ticks * 10000000 : 1.0)) + static gint rspamd_ast_priority_cmp (GNode *a, GNode *b) { struct rspamd_expression_elt *ea = a->data, *eb = b->data; + gdouble w1, w2; + + /* Special logic for atoms */ + if (ea->type == ELT_ATOM && eb->type == ELT_ATOM && + ea->priority == eb->priority) { + w1 = ATOM_PRIORITY (ea); + w2 = ATOM_PRIORITY (eb); - return ea->priority - eb->priority; + ea->p.atom->hits = 0; + ea->p.atom->avg_ticks = 0.0; + + return w1 - w2; + } + else { + return ea->priority - eb->priority; + } } static gboolean @@ -843,6 +860,10 @@ rspamd_ast_process_node (struct rspamd_expression *expr, gint flags, GNode *node elt->value = expr->subr->process (data, elt->p.atom); + if (elt->value) { + elt->p.atom->hits ++; + } + if (calc_ticks) { t2 = rspamd_get_ticks (); elt->p.atom->avg_ticks += ((t2 - t1) - elt->p.atom->avg_ticks) / |