add some ctx cleanup

This commit is contained in:
Green Sky 2024-10-31 13:08:35 +01:00
parent a4092298fb
commit 14f751af0b
No known key found for this signature in database
3 changed files with 18 additions and 1 deletions

View File

@ -11,8 +11,8 @@
#include <limits> #include <limits>
#include <iostream> #include <iostream>
static std::unique_ptr<MessageFragmentStore> g_mfs = nullptr;
static std::unique_ptr<Backends::FilesystemStorage> g_fsb = nullptr; static std::unique_ptr<Backends::FilesystemStorage> g_fsb = nullptr;
static std::unique_ptr<MessageFragmentStore> g_mfs = nullptr;
constexpr const char* plugin_name = "MessageFragmentStore"; 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) { SOLANA_PLUGIN_EXPORT float solana_plugin_tick(float time_delta) {
// HACK
static bool scan_triggered {false}; static bool scan_triggered {false};
if (!scan_triggered) { if (!scan_triggered) {
g_fsb->scanAsync(); g_fsb->scanAsync();

View File

@ -81,6 +81,7 @@ void MessageFragmentStore::handleMessage(const Message3Handle& m) {
} }
_potentially_dirty_contacts.emplace(m.registry()->ctx().get<Contact3>()); // always mark dirty here _potentially_dirty_contacts.emplace(m.registry()->ctx().get<Contact3>()); // always mark dirty here
_touched_contacts.emplace(m.registry()->ctx().get<Contact3>());
if (m.any_of<Message::Components::ViewCurserBegin, Message::Components::ViewCurserEnd>()) { if (m.any_of<Message::Components::ViewCurserBegin, Message::Components::ViewCurserEnd>()) {
// not an actual message, but we probalby need to check and see if we need to load fragments // 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"; //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: check if file object has id
// TODO: use fid, saving full fuid for every message consumes alot of memory (and heap frag) // TODO: use fid, saving full fuid for every message consumes alot of memory (and heap frag)
if (!m.all_of<Message::Components::MFSObj>()) { if (!m.all_of<Message::Components::MFSObj>()) {
std::cout << "MFS: new msg missing Object\n"; std::cout << "MFS: new msg missing Object\n";
@ -538,6 +540,15 @@ MessageFragmentStore::~MessageFragmentStore(void) {
_fs_ignore_event = false; _fs_ignore_event = false;
_frag_save_queue.pop_front(); // pop unconditionally _frag_save_queue.pop_front(); // pop unconditionally
} }
for (const auto c : _touched_contacts) {
auto* mr_ptr = static_cast<const RegistryMessageModelI&>(_rmm).get(c);
if (mr_ptr != nullptr) {
mr_ptr->ctx().erase<Message::Contexts::OpenFragments>();
mr_ptr->ctx().erase<Message::Contexts::ContactFragments>();
mr_ptr->ctx().erase<Message::Contexts::LoadedContactFragments>();
}
}
} }
// checks range against all cursers in msgreg // 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 // TODO: this is an erroious path
return false; return false;
} }
_touched_contacts.emplace(frag_contact);
if (!msg_reg->ctx().contains<Message::Contexts::ContactFragments>()) { if (!msg_reg->ctx().contains<Message::Contexts::ContactFragments>()) {
msg_reg->ctx().emplace<Message::Contexts::ContactFragments>(); msg_reg->ctx().emplace<Message::Contexts::ContactFragments>();
@ -928,6 +940,7 @@ bool MessageFragmentStore::onEvent(const ObjectStore::Events::ObjectUpdate& e) {
// TODO: this is an erroious path // TODO: this is an erroious path
return false; return false;
} }
_touched_contacts.emplace(frag_contact);
if (!msg_reg->ctx().contains<Message::Contexts::ContactFragments>()) { if (!msg_reg->ctx().contains<Message::Contexts::ContactFragments>()) {
msg_reg->ctx().emplace<Message::Contexts::ContactFragments>(); msg_reg->ctx().emplace<Message::Contexts::ContactFragments>();

View File

@ -86,6 +86,9 @@ class MessageFragmentStore : public RegistryMessageModelEventI, public ObjectSto
// so we need to keep them dirty until nothing was loaded. // so we need to keep them dirty until nothing was loaded.
entt::dense_set<Contact3> _potentially_dirty_contacts; entt::dense_set<Contact3> _potentially_dirty_contacts;
// for cleaning up the ctx vars we create
entt::dense_set<Contact3> _touched_contacts;
public: public:
MessageFragmentStore( MessageFragmentStore(
Contact3Registry& cr, Contact3Registry& cr,