]> source.dussan.org Git - rspamd.git/commitdiff
Implement frequency incrementing.
authorVsevolod Stakhov <vsevolod@highsecure.ru>
Thu, 28 May 2015 16:20:47 +0000 (17:20 +0100)
committerVsevolod Stakhov <vsevolod@highsecure.ru>
Thu, 28 May 2015 16:20:47 +0000 (17:20 +0100)
src/libmime/filter.c
src/libserver/symbols_cache.c
src/libserver/symbols_cache.h

index b939a1785d354e0c29342c1fe8435998332f17fc..1469cdfd7df8b42056a9913aadea94c93c563469 100644 (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) {
index 2ee753fdb50a7318833e31ef533c4153e8984ab9..8b0e1dcad9e6f741790cd5f7b8c36dd45855a3b8 100644 (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 ++;
+               }
+       }
+}
index 013dc91ed216b4e9465f463ae51ca85c10576f7b..878d0a0bfc904d427c184ee64c630a0dc2945e49 100644 (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