commit 2cc0f80: [Fix] Move metric and symcache link from validation to the init stage

Vsevolod Stakhov vsevolod at highsecure.ru
Tue Apr 6 15:42:04 UTC 2021


Author: Vsevolod Stakhov
Date: 2021-04-06 16:40:16 +0100
URL: https://github.com/rspamd/rspamd/commit/2cc0f80707a0d34e6c5b155aa9f49721383f5f4c (HEAD -> master)

[Fix] Move metric and symcache link from validation to the init stage

---
 src/libserver/rspamd_symcache.c | 46 +++++++++++++++++++++--------------------
 1 file changed, 24 insertions(+), 22 deletions(-)

diff --git a/src/libserver/rspamd_symcache.c b/src/libserver/rspamd_symcache.c
index 6615cb14e..aeab2de10 100644
--- a/src/libserver/rspamd_symcache.c
+++ b/src/libserver/rspamd_symcache.c
@@ -1375,6 +1375,24 @@ rspamd_symcache_new (struct rspamd_config *cfg)
 	return cache;
 }
 
+static void
+rspamd_symcache_metric_connect_cb (gpointer k, gpointer v, gpointer ud)
+{
+	struct rspamd_symcache *cache = (struct rspamd_symcache *)ud;
+	const gchar *sym = k;
+	struct rspamd_symbol *s = (struct rspamd_symbol *)v;
+	gdouble weight;
+	struct rspamd_symcache_item *item;
+
+	weight = *s->weight_ptr;
+	item = g_hash_table_lookup (cache->items_by_symbol, sym);
+
+	if (item) {
+		item->st->weight = weight;
+		s->cache_item = item;
+	}
+}
+
 gboolean
 rspamd_symcache_init (struct rspamd_symcache *cache)
 {
@@ -1393,6 +1411,12 @@ rspamd_symcache_init (struct rspamd_symcache *cache)
 	/* Copy saved cache entries */
 	res = rspamd_symcache_load_items (cache, cache->cfg->cache_filename);
 	rspamd_symcache_post_init (cache);
+	/* Connect metric symbols with symcache symbols */
+	if (cache->cfg->symbols) {
+		g_hash_table_foreach(cache->cfg->symbols,
+				rspamd_symcache_metric_connect_cb,
+				cache);
+	}
 
 	return res;
 }
@@ -1482,24 +1506,6 @@ rspamd_symcache_validate_cb (gpointer k, gpointer v, gpointer ud)
 	cache->total_weight += fabs (item->st->weight);
 }
 
-static void
-rspamd_symcache_metric_validate_cb (gpointer k, gpointer v, gpointer ud)
-{
-	struct rspamd_symcache *cache = (struct rspamd_symcache *)ud;
-	const gchar *sym = k;
-	struct rspamd_symbol *s = (struct rspamd_symbol *)v;
-	gdouble weight;
-	struct rspamd_symcache_item *item;
-
-	weight = *s->weight_ptr;
-	item = g_hash_table_lookup (cache->items_by_symbol, sym);
-
-	if (item) {
-		item->st->weight = weight;
-		s->cache_item = item;
-	}
-}
-
 gboolean
 rspamd_symcache_validate (struct rspamd_symcache *cache,
 						  struct rspamd_config *cfg,
@@ -1516,10 +1522,6 @@ rspamd_symcache_validate (struct rspamd_symcache *cache,
 		return FALSE;
 	}
 
-	/* Now adjust symbol weights according to default metric */
-	g_hash_table_foreach (cfg->symbols,
-			rspamd_symcache_metric_validate_cb,
-			cache);
 
 	g_hash_table_foreach (cache->items_by_symbol,
 			rspamd_symcache_validate_cb,


More information about the Commits mailing list