aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorVsevolod Stakhov <vsevolod@highsecure.ru>2015-05-28 17:20:47 +0100
committerVsevolod Stakhov <vsevolod@highsecure.ru>2015-05-28 17:20:47 +0100
commitec9032622aded1dc2fed4a758943e6ebccda4f98 (patch)
tree6a1a3f402867db34e10ad8088db87f58ffba0709
parent4e0dec94f6da1757a1e3b320bb98ba8f0bb36728 (diff)
downloadrspamd-ec9032622aded1dc2fed4a758943e6ebccda4f98.tar.gz
rspamd-ec9032622aded1dc2fed4a758943e6ebccda4f98.zip
Implement frequency incrementing.
-rw-r--r--src/libmime/filter.c2
-rw-r--r--src/libserver/symbols_cache.c22
-rw-r--r--src/libserver/symbols_cache.h8
3 files changed, 31 insertions, 1 deletions
diff --git a/src/libmime/filter.c b/src/libmime/filter.c
index b939a1785..1469cdfd7 100644
--- a/src/libmime/filter.c
+++ b/src/libmime/filter.c
@@ -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) {
diff --git a/src/libserver/symbols_cache.c b/src/libserver/symbols_cache.c
index 2ee753fdb..8b0e1dcad 100644
--- a/src/libserver/symbols_cache.c
+++ b/src/libserver/symbols_cache.c
@@ -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 ++;
+ }
+ }
+}
diff --git a/src/libserver/symbols_cache.h b/src/libserver/symbols_cache.h
index 013dc91ed..878d0a0bf 100644
--- a/src/libserver/symbols_cache.h
+++ b/src/libserver/symbols_cache.h
@@ -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