GPtrArray *items_by_id;
struct symcache_order *items_by_order;
GPtrArray *filters;
+ GPtrArray *prefilters_empty;
GPtrArray *prefilters;
GPtrArray *postfilters;
GPtrArray *composites;
enum rspamd_cache_savepoint_stage {
RSPAMD_CACHE_PASS_INIT = 0,
+ RSPAMD_CACHE_PASS_PREFILTERS_EMPTY,
RSPAMD_CACHE_PASS_PREFILTERS,
RSPAMD_CACHE_PASS_FILTERS,
RSPAMD_CACHE_PASS_POSTFILTERS,
}
}
+ g_ptr_array_sort_with_data (cache->prefilters_empty, prefilters_cmp, cache);
g_ptr_array_sort_with_data (cache->prefilters, prefilters_cmp, cache);
g_ptr_array_sort_with_data (cache->postfilters, postfilters_cmp, cache);
g_ptr_array_sort_with_data (cache->idempotent, postfilters_cmp, cache);
g_assert (parent == -1);
if (item->type & SYMBOL_TYPE_PREFILTER) {
- g_ptr_array_add (cache->prefilters, item);
- item->container = cache->prefilters;
+ if (item->type & SYMBOL_TYPE_EMPTY) {
+ /* Executed before mime parsing stage */
+ g_ptr_array_add (cache->prefilters_empty, item);
+ item->container = cache->prefilters_empty;
+ }
+ else {
+ g_ptr_array_add (cache->prefilters, item);
+ item->container = cache->prefilters;
+ }
}
else if (item->type & SYMBOL_TYPE_IDEMPOTENT) {
g_ptr_array_add (cache->idempotent, item);
rspamd_mempool_delete (cache->static_pool);
g_ptr_array_free (cache->filters, TRUE);
g_ptr_array_free (cache->prefilters, TRUE);
+ g_ptr_array_free (cache->prefilters_empty, TRUE);
g_ptr_array_free (cache->postfilters, TRUE);
g_ptr_array_free (cache->idempotent, TRUE);
g_ptr_array_free (cache->composites, TRUE);
cache->items_by_id = g_ptr_array_new ();
cache->filters = g_ptr_array_new ();
cache->prefilters = g_ptr_array_new ();
+ cache->prefilters_empty = g_ptr_array_new ();
cache->postfilters = g_ptr_array_new ();
cache->idempotent = g_ptr_array_new ();
cache->composites = g_ptr_array_new ();
struct rspamd_symcache_item *item = NULL;
struct rspamd_symcache_dynamic_item *dyn_item;
struct cache_savepoint *checkpoint;
+ GPtrArray *sel;
gint i;
gboolean all_done;
gint saved_priority;
+ enum rspamd_cache_savepoint_stage next;
guint start_events_pending;
g_assert (cache != NULL);
switch (checkpoint->pass) {
case RSPAMD_CACHE_PASS_INIT:
case RSPAMD_CACHE_PASS_PREFILTERS:
+ case RSPAMD_CACHE_PASS_PREFILTERS_EMPTY:
/* Check for prefilters */
saved_priority = G_MININT;
all_done = TRUE;
- for (i = 0; i < (gint)cache->prefilters->len; i ++) {
- item = g_ptr_array_index (cache->prefilters, i);
+ if (checkpoint->pass != RSPAMD_CACHE_PASS_PREFILTERS) {
+ sel = cache->prefilters_empty;
+ next = RSPAMD_CACHE_PASS_PREFILTERS;
+ checkpoint->pass = RSPAMD_CACHE_PASS_PREFILTERS_EMPTY;
+ }
+ else {
+ sel = cache->prefilters;
+ next = RSPAMD_CACHE_PASS_FILTERS;
+ }
+
+
+ for (i = 0; i < (gint)sel->len; i ++) {
+ item = g_ptr_array_index (sel, i);
dyn_item = rspamd_symcache_get_dynamic (checkpoint, item);
if (RSPAMD_TASK_IS_SKIPPED (task)) {
* Delay further checks as we have higher
* priority filters to be processed
*/
- checkpoint->pass = RSPAMD_CACHE_PASS_PREFILTERS;
-
return TRUE;
}
}
}
}
- if (all_done || stage == RSPAMD_TASK_STAGE_FILTERS) {
- checkpoint->pass = RSPAMD_CACHE_PASS_FILTERS;
+ if (all_done || stage == next) {
+ checkpoint->pass = next;
}
- if (stage == RSPAMD_TASK_STAGE_FILTERS) {
+ if (stage == next) {
return rspamd_symcache_process_symbols (task, cache, stage);
}
RSPAMD_TASK_STAGE_CONNECT = (1u << 0u),
RSPAMD_TASK_STAGE_ENVELOPE = (1u << 1u),
RSPAMD_TASK_STAGE_READ_MESSAGE = (1u << 2u),
- RSPAMD_TASK_STAGE_PRE_FILTERS = (1u << 3u),
+ RSPAMD_TASK_STAGE_PRE_FILTERS_EMPTY = (1u << 3u),
RSPAMD_TASK_STAGE_PROCESS_MESSAGE = (1u << 4u),
- RSPAMD_TASK_STAGE_FILTERS = (1u << 5u),
- RSPAMD_TASK_STAGE_CLASSIFIERS_PRE = (1u << 6u),
- RSPAMD_TASK_STAGE_CLASSIFIERS = (1u << 7u),
- RSPAMD_TASK_STAGE_CLASSIFIERS_POST = (1u << 8u),
- RSPAMD_TASK_STAGE_COMPOSITES = (1u << 9u),
- RSPAMD_TASK_STAGE_POST_FILTERS = (1u << 10u),
- RSPAMD_TASK_STAGE_LEARN_PRE = (1u << 11u),
- RSPAMD_TASK_STAGE_LEARN = (1u << 12u),
- RSPAMD_TASK_STAGE_LEARN_POST = (1u << 13u),
- RSPAMD_TASK_STAGE_COMPOSITES_POST = (1u << 14u),
- RSPAMD_TASK_STAGE_IDEMPOTENT = (1u << 15u),
- RSPAMD_TASK_STAGE_DONE = (1u << 16u),
- RSPAMD_TASK_STAGE_REPLIED = (1u << 17u)
+ RSPAMD_TASK_STAGE_PRE_FILTERS = (1u << 5u),
+ RSPAMD_TASK_STAGE_FILTERS = (1u << 6u),
+ RSPAMD_TASK_STAGE_CLASSIFIERS_PRE = (1u << 7u),
+ RSPAMD_TASK_STAGE_CLASSIFIERS = (1u << 8u),
+ RSPAMD_TASK_STAGE_CLASSIFIERS_POST = (1u << 9u),
+ RSPAMD_TASK_STAGE_COMPOSITES = (1u << 10u),
+ RSPAMD_TASK_STAGE_POST_FILTERS = (1u << 11u),
+ RSPAMD_TASK_STAGE_LEARN_PRE = (1u << 12u),
+ RSPAMD_TASK_STAGE_LEARN = (1u << 13u),
+ RSPAMD_TASK_STAGE_LEARN_POST = (1u << 14u),
+ RSPAMD_TASK_STAGE_COMPOSITES_POST = (1u << 15u),
+ RSPAMD_TASK_STAGE_IDEMPOTENT = (1u << 16u),
+ RSPAMD_TASK_STAGE_DONE = (1u << 17u),
+ RSPAMD_TASK_STAGE_REPLIED = (1u << 18u)
};
#define RSPAMD_TASK_PROCESS_ALL (RSPAMD_TASK_STAGE_CONNECT | \