From: Dmitriy Alekseev <1865999+dragoangel@users.noreply.github.com> Date: Thu, 30 Jul 2026 14:58:49 +0000 (+0200) Subject: [Minor] Do not fetch a hyperscan database that is already installed X-Git-Url: http://git.ipfire.org/gitweb.cgi?a=commitdiff_plain;h=f53930d0338cfaaf55fc4caa1679b69bda3803bc;p=thirdparty%2Frspamd.git [Minor] Do not fetch a hyperscan database that is already installed 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. --- diff --git a/src/libserver/maps/map_helpers.c b/src/libserver/maps/map_helpers.c index 32709c3782..0eb543c5e4 100644 --- a/src/libserver/maps/map_helpers.c +++ b/src/libserver/maps/map_helpers.c @@ -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 */