]> source.dussan.org Git - rspamd.git/commitdiff
[Minor] Save list of children for normal symbols with dependent virtual symbols
authorVsevolod Stakhov <vsevolod@rspamd.com>
Tue, 5 Jul 2022 19:08:22 +0000 (20:08 +0100)
committerVsevolod Stakhov <vsevolod@rspamd.com>
Tue, 5 Jul 2022 19:08:22 +0000 (20:08 +0100)
src/libserver/symcache/symcache_impl.cxx
src/libserver/symcache/symcache_item.hxx
src/libserver/symcache/symcache_periodic.hxx

index 52a2042b119a1adecf41ad0bcaa5759725434947..7a6878faa901a4a71e16992c55e569ca87567728 100644 (file)
@@ -688,12 +688,19 @@ auto symcache::add_virtual_symbol(std::string_view name, int parent_id, enum rsp
                return -1;
        }
 
+       if (items_by_id.size() < parent_id) {
+               msg_err_cache("parent id %d is out of bounds for virtual symbol %s", parent_id, name.data());
+               return -1;
+       }
+
        auto id = items_by_id.size();
 
        auto item = cache_item::create_with_virtual(static_pool,
                        id,
                        std::string{name},
                        parent_id, real_type_pair.first, real_type_pair.second);
+       auto &parent = items_by_id[parent_id];
+       parent->add_child(item);
        items_by_symbol[item->get_name()] = item;
        get_item_specific_vector(*item).push_back(item);
        items_by_id.push_back(item);
index 70203770a41b34442475ae1ca4eaf039158ffcac..2c2072fd364646c64ce3e187b9464968dc2a7b28 100644 (file)
@@ -110,6 +110,7 @@ class normal_item {
 private:
        symbol_func_t func;
        void *user_data;
+       std::vector<cache_item_ptr> virtual_children;
        std::vector<item_condition> conditions;
 public:
        explicit normal_item(symbol_func_t _func, void *_user_data) : func(_func), user_data(_user_data)
@@ -134,6 +135,10 @@ public:
        auto get_cbdata() const -> auto {
                return user_data;
        }
+
+       auto add_child(const cache_item_ptr &ptr) -> void {
+               virtual_children.push_back(ptr);
+       }
 };
 
 class virtual_item {
@@ -395,6 +400,21 @@ public:
         */
        auto get_augmentation_weight() const -> int;
 
+       /**
+        * Add a virtual symbol as a child of some normal symbol
+        * @param ptr
+        */
+       auto add_child(const cache_item_ptr &ptr) -> void {
+               if (std::holds_alternative<normal_item>(specific)) {
+                       auto &filter_data = std::get<normal_item>(specific);
+
+                       filter_data.add_child(ptr);
+               }
+               else {
+                       g_assert("add child is called for a virtual symbol!");
+               }
+       }
+
 private:
        /**
         * Constructor for a normal symbols with callback
index 2719fca25b53ebde05ecb83f19885f5646106d62..31c94c41370dbe4130036630bacc16bb3515ce1a 100644 (file)
@@ -63,7 +63,6 @@ public:
 
        static void resort_cb(EV_P_ ev_timer *w, int _revents) {
                auto *cbdata = (struct cache_refresh_cbdata *)w->data;
-               static const double decay_rate = 0.25;
 
                auto log_tag = [&]() { return cbdata->cache->log_tag(); };