Browse Source

Implement frequency incrementing.

tags/1.0.0
Vsevolod Stakhov 9 years ago
parent
commit
ec9032622a
3 changed files with 31 additions and 1 deletions
  1. 1
    1
      src/libmime/filter.c
  2. 22
    0
      src/libserver/symbols_cache.c
  3. 8
    0
      src/libserver/symbols_cache.h

+ 1
- 1
src/libmime/filter.c View File

@@ -297,7 +297,7 @@ insert_result_common (struct rspamd_task *task,

/* Process cache item */
if (task->cfg->cache) {
/* XXX: increase frequency here */
rspamd_symbols_cache_inc_frequency (task->cfg->cache, symbol);
}

if (opts != NULL) {

+ 22
- 0
src/libserver/symbols_cache.c View File

@@ -865,3 +865,25 @@ rspamd_symbols_cache_start_refresh (struct symbols_cache * cache,
double_to_tv (tm, &tv);
event_add (&cache->resort_ev, &tv);
}

void
rspamd_symbols_cache_inc_frequency (struct symbols_cache *cache,
const gchar *symbol)
{
struct cache_item *item, *parent;

g_assert (cache != NULL);

item = g_hash_table_lookup (cache->items_by_symbol, symbol);

if (item != NULL) {
/* We assume ++ as atomic op */
item->frequency ++;

/* For virtual symbols we also increase counter for parent */
if (item->parent != -1) {
parent = g_ptr_array_index (cache->items_by_order, item->parent);
parent->frequency ++;
}
}
}

+ 8
- 0
src/libserver/symbols_cache.h View File

@@ -165,4 +165,12 @@ ucl_object_t *rspamd_symbols_cache_counters (struct symbols_cache * cache);
void rspamd_symbols_cache_start_refresh (struct symbols_cache * cache,
struct event_base *ev_base);

/**
* Increases counter for a specific symbol
* @param cache
* @param symbol
*/
void rspamd_symbols_cache_inc_frequency (struct symbols_cache *cache,
const gchar *symbol);

#endif

Loading…
Cancel
Save