]> git.ipfire.org Git - thirdparty/rspamd.git/commitdiff
[Minor] Do not fetch a hyperscan database that is already installed 6161/head
authorDmitriy Alekseev <1865999+dragoangel@users.noreply.github.com>
Thu, 30 Jul 2026 14:58:49 +0000 (16:58 +0200)
committerDmitriy Alekseev <1865999+dragoangel@users.noreply.github.com>
Thu, 30 Jul 2026 16:02:01 +0000 (18:02 +0200)
A map is put in the compilation queue by its read callback and announced by a
notification once the database is there, and both paths load it, so every map
update cost twice the traffic: megabytes for a map of a few thousand patterns.

Skip the load when the helper already has a database. That cannot keep a stale
one: every read allocates a helper of its own with no database at all, its
patterns never change afterwards, and a database only ever gets installed for
the content of that very helper, the load verifying the digest before it does
so.

src/libserver/maps/map_helpers.c

index 32709c3782f4cd5da0ed3771729c521ea640fb3d..0eb543c5e4388709584ba34f4434d0547c09265f 100644 (file)
@@ -2517,6 +2517,9 @@ void rspamd_regexp_map_load_from_cache_async(struct rspamd_regexp_map_helper *re
        /* All file operations go through Lua backend */
        g_assert(rspamd_hs_cache_has_lua_backend());
 
+       /* msg_debug_map expects a `map` in scope */
+       struct rspamd_map *map = re_map->map;
+
        char cache_key[rspamd_cryptobox_HASHBYTES * 2 + 1];
        rspamd_snprintf(cache_key, sizeof(cache_key), "%*xs",
                                        (int) rspamd_cryptobox_HASHBYTES / 2, re_map->re_digest);
@@ -2526,11 +2529,19 @@ void rspamd_regexp_map_load_from_cache_async(struct rspamd_regexp_map_helper *re
        /* Same tag the map keeps for its current content, see rspamd_regexp_list_fin */
        memcpy(&map_digest, re_map->re_digest, sizeof(map_digest));
 
-       if (rspamd_regexp_map_load_inflight(map_digest, TRUE)) {
-               struct rspamd_map *map = re_map->map;
+       if (re_map->hs_db != NULL) {
+               /* A helper belongs to one version of the content, so this one is ours */
+               msg_debug_map("hyperscan database is already installed for %s", map->name);
+
+               if (cb) {
+                       cb(TRUE, ud);
+               }
 
-               msg_debug_map("the very database is already being loaded for %s",
-                                         map->name);
+               return;
+       }
+
+       if (rspamd_regexp_map_load_inflight(map_digest, TRUE)) {
+               msg_debug_map("the very database is already being loaded for %s", map->name);
 
                if (cb) {
                        cb(FALSE, ud);
@@ -3011,6 +3022,7 @@ void rspamd_regexp_map_compile_pending_async(struct rspamd_worker *worker,
        (void) worker;
        (void) event_loop;
        (void) cache_dir;
+       (void) flags;
 }
 
 #endif /* WITH_HYPERSCAN */