From 14f751af0b4cd3176427683c8108c87325e9c48b Mon Sep 17 00:00:00 2001 From: Green Sky Date: Thu, 31 Oct 2024 13:08:35 +0100 Subject: [PATCH] add some ctx cleanup --- plugins/plugin_mfs_wip.cpp | 3 ++- .../message_fragment_store.cpp | 13 +++++++++++++ .../message_fragment_store.hpp | 3 +++ 3 files changed, 18 insertions(+), 1 deletion(-) diff --git a/plugins/plugin_mfs_wip.cpp b/plugins/plugin_mfs_wip.cpp index 7c18f57..e120bf2 100644 --- a/plugins/plugin_mfs_wip.cpp +++ b/plugins/plugin_mfs_wip.cpp @@ -11,8 +11,8 @@ #include #include -static std::unique_ptr g_mfs = nullptr; static std::unique_ptr g_fsb = nullptr; +static std::unique_ptr g_mfs = nullptr; constexpr const char* plugin_name = "MessageFragmentStore"; @@ -62,6 +62,7 @@ SOLANA_PLUGIN_EXPORT void solana_plugin_stop(void) { } SOLANA_PLUGIN_EXPORT float solana_plugin_tick(float time_delta) { + // HACK static bool scan_triggered {false}; if (!scan_triggered) { g_fsb->scanAsync(); diff --git a/src/solanaceae/message_fragment_store/message_fragment_store.cpp b/src/solanaceae/message_fragment_store/message_fragment_store.cpp index 27cf66b..c91bc8a 100644 --- a/src/solanaceae/message_fragment_store/message_fragment_store.cpp +++ b/src/solanaceae/message_fragment_store/message_fragment_store.cpp @@ -81,6 +81,7 @@ void MessageFragmentStore::handleMessage(const Message3Handle& m) { } _potentially_dirty_contacts.emplace(m.registry()->ctx().get()); // always mark dirty here + _touched_contacts.emplace(m.registry()->ctx().get()); if (m.any_of()) { // not an actual message, but we probalby need to check and see if we need to load fragments //std::cout << "MFS: new or updated curser\n"; @@ -94,6 +95,7 @@ void MessageFragmentStore::handleMessage(const Message3Handle& m) { } // TODO: check if file object has id + // TODO: use fid, saving full fuid for every message consumes alot of memory (and heap frag) if (!m.all_of()) { std::cout << "MFS: new msg missing Object\n"; @@ -538,6 +540,15 @@ MessageFragmentStore::~MessageFragmentStore(void) { _fs_ignore_event = false; _frag_save_queue.pop_front(); // pop unconditionally } + + for (const auto c : _touched_contacts) { + auto* mr_ptr = static_cast(_rmm).get(c); + if (mr_ptr != nullptr) { + mr_ptr->ctx().erase(); + mr_ptr->ctx().erase(); + mr_ptr->ctx().erase(); + } + } } // checks range against all cursers in msgreg @@ -872,6 +883,7 @@ bool MessageFragmentStore::onEvent(const ObjectStore::Events::ObjectConstruct& e // TODO: this is an erroious path return false; } + _touched_contacts.emplace(frag_contact); if (!msg_reg->ctx().contains()) { msg_reg->ctx().emplace(); @@ -928,6 +940,7 @@ bool MessageFragmentStore::onEvent(const ObjectStore::Events::ObjectUpdate& e) { // TODO: this is an erroious path return false; } + _touched_contacts.emplace(frag_contact); if (!msg_reg->ctx().contains()) { msg_reg->ctx().emplace(); diff --git a/src/solanaceae/message_fragment_store/message_fragment_store.hpp b/src/solanaceae/message_fragment_store/message_fragment_store.hpp index 22c3734..68411ee 100644 --- a/src/solanaceae/message_fragment_store/message_fragment_store.hpp +++ b/src/solanaceae/message_fragment_store/message_fragment_store.hpp @@ -86,6 +86,9 @@ class MessageFragmentStore : public RegistryMessageModelEventI, public ObjectSto // so we need to keep them dirty until nothing was loaded. entt::dense_set _potentially_dirty_contacts; + // for cleaning up the ctx vars we create + entt::dense_set _touched_contacts; + public: MessageFragmentStore( Contact3Registry& cr,