port to contact4

This commit is contained in:
Green Sky 2025-03-10 16:47:06 +01:00
parent 2647ede775
commit dc0af844a1
No known key found for this signature in database
GPG Key ID: DBE05085D874AB4A
5 changed files with 37 additions and 33 deletions

View File

@ -34,7 +34,7 @@ SOLANA_PLUGIN_EXPORT uint32_t solana_plugin_start(struct SolanaAPI* solana_api)
}
try {
auto* cr = PLUG_RESOLVE_INSTANCE_VERSIONED(Contact3Registry, "1");
auto* cs = PLUG_RESOLVE_INSTANCE(ContactStore4I);
auto* rmm = PLUG_RESOLVE_INSTANCE(RegistryMessageModelI);
auto* os = PLUG_RESOLVE_INSTANCE(ObjectStore2);
auto* msnj = PLUG_RESOLVE_INSTANCE(MessageSerializerNJ);
@ -42,7 +42,7 @@ SOLANA_PLUGIN_EXPORT uint32_t solana_plugin_start(struct SolanaAPI* solana_api)
// static store, could be anywhere tho
// construct with fetched dependencies
g_fsb = std::make_unique<Backends::FilesystemStorage>(*os, "test2_message_store/"); // TODO: use config?
g_mfs = std::make_unique<MessageFragmentStore>(*cr, *rmm, *os, *g_fsb, *g_fsb, *msnj);
g_mfs = std::make_unique<MessageFragmentStore>(*cs, *rmm, *os, *g_fsb, *g_fsb, *msnj);
// register types
PLUG_PROVIDE_INSTANCE(MessageFragmentStore, plugin_name, g_mfs.get());

View File

@ -28,6 +28,7 @@ add_executable(convert_message_object_store
)
target_link_libraries(convert_message_object_store PUBLIC
solanaceae_contact_impl
solanaceae_object_store
solanaceae_object_store_backend_filesystem
solanaceae_message_fragment_store

View File

@ -1,3 +1,4 @@
#include <solanaceae/contact/contact_store_impl.hpp>
#include <solanaceae/object_store/object_store.hpp>
#include <solanaceae/object_store/backends/filesystem_storage.hpp>
#include <solanaceae/object_store/meta_components.hpp>
@ -35,14 +36,14 @@ int main(int argc, const char** argv) {
Backends::FilesystemStorage fsb_src(os_src, argv[1]);
Backends::FilesystemStorage fsb_dst(os_dst, argv[2]);
Contact3Registry cr; // dummy
RegistryMessageModelImpl rmm(cr); // dummy
ContactStore4Impl cs; // dummy
RegistryMessageModelImpl rmm(cs); // dummy
// they only exist for the serializers (for now)
// TODO: version
MessageSerializerNJ msnj_src{cr, os_src, {}, {}};
MessageFragmentStore mfs_src(cr, rmm, os_src, fsb_src, fsb_src, msnj_src);
MessageSerializerNJ msnj_dst{cr, os_dst, {}, {}};
MessageFragmentStore mfs_dst(cr, rmm, os_dst, fsb_dst, fsb_dst, msnj_dst);
MessageSerializerNJ msnj_src{cs, os_src, {}, {}};
MessageFragmentStore mfs_src(cs, rmm, os_src, fsb_src, fsb_src, msnj_src);
MessageSerializerNJ msnj_dst{cs, os_dst, {}, {}};
MessageFragmentStore mfs_dst(cs, rmm, os_dst, fsb_dst, fsb_dst, msnj_dst);
// add message fragment store too (adds meta?)

View File

@ -9,6 +9,8 @@
#include <solanaceae/util/utils.hpp>
#include <solanaceae/util/time.hpp>
#include <solanaceae/contact/contact_store_i.hpp>
#include <solanaceae/contact/components.hpp>
#include <solanaceae/message3/components.hpp>
#include <solanaceae/message3/contact_components.hpp>
@ -37,7 +39,7 @@ namespace ObjectStore::Components {
// cache the contact for faster lookups
struct MessagesContactEntity {
Contact3 e {entt::null};
Contact4 e {entt::null};
};
}
} // ObjectStore::Component
@ -83,8 +85,8 @@ void MessageFragmentStore::handleMessage(const Message3Handle& m) {
return; // we only handle msg with ts
}
_potentially_dirty_contacts.emplace(m.registry()->ctx().get<Contact3>()); // always mark dirty here
_touched_contacts.emplace(m.registry()->ctx().get<Contact3>());
_potentially_dirty_contacts.emplace(m.registry()->ctx().get<Contact4>()); // always mark dirty here
_touched_contacts.emplace(m.registry()->ctx().get<Contact4>());
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
//std::cout << "MFS: new or updated curser\n";
@ -206,9 +208,9 @@ void MessageFragmentStore::handleMessage(const Message3Handle& m) {
new_ts_range.end = msg_ts;
{
const auto msg_reg_contact = m.registry()->ctx().get<Contact3>();
if (_cr.all_of<Contact::Components::ID>(msg_reg_contact)) {
fh.emplace<ObjComp::MessagesContact>(_cr.get<Contact::Components::ID>(msg_reg_contact).data);
const auto msg_reg_contact = m.registry()->ctx().get<Contact4>();
if (_cs.registry().all_of<Contact::Components::ID>(msg_reg_contact)) {
fh.emplace<ObjComp::MessagesContact>(_cs.registry().get<Contact::Components::ID>(msg_reg_contact).data);
} else {
// ? rage quit?
}
@ -364,10 +366,10 @@ void MessageFragmentStore::loadFragment(Message3Registry& reg, ObjectHandle fh)
Message3 dup_msg {entt::null};
{
// get comparator from contact
if (reg.ctx().contains<Contact3>()) {
const auto c = reg.ctx().get<Contact3>();
if (_cr.all_of<Contact::Components::MessageIsSame>(c)) {
auto& comp = _cr.get<Contact::Components::MessageIsSame>(c).comp;
if (reg.ctx().contains<Contact4>()) {
const auto c = reg.ctx().get<Contact4>();
if (_cs.registry().all_of<Contact::Components::MessageIsSame>(c)) {
auto& comp = _cs.registry().get<Contact::Components::MessageIsSame>(c).comp;
// walking EVERY existing message OOF
// this needs optimizing
for (const Message3 other_msg : reg.view<Message::Components::Timestamp, Message::Components::ContactFrom, Message::Components::ContactTo>()) {
@ -504,13 +506,13 @@ bool MessageFragmentStore::syncFragToStorage(ObjectHandle fh, Message3Registry&
}
MessageFragmentStore::MessageFragmentStore(
Contact3Registry& cr,
ContactStore4I& cs,
RegistryMessageModelI& rmm,
ObjectStore2& os,
StorageBackendIMeta& sbm,
StorageBackendIAtomic& sba,
MessageSerializerNJ& scnj
) : _cr(cr), _rmm(rmm), _rmm_sr(_rmm.newSubRef(this)), _os(os), _os_sr(_os.newSubRef(this)), _sbm(sbm), _sba(sba), _scnj(scnj) {
) : _cs(cs), _rmm(rmm), _rmm_sr(_rmm.newSubRef(this)), _os(os), _os_sr(_os.newSubRef(this)), _sbm(sbm), _sba(sba), _scnj(scnj) {
_rmm_sr
.subscribe(RegistryMessageModel_Event::message_construct)
.subscribe(RegistryMessageModel_Event::message_updated)
@ -867,17 +869,17 @@ bool MessageFragmentStore::onEvent(const ObjectStore::Events::ObjectConstruct& e
// TODO: are we sure it is a *new* fragment?
Contact3 frag_contact = entt::null;
Contact4 frag_contact = entt::null;
{ // get contact
const auto& frag_contact_id = e.e.get<ObjComp::MessagesContact>().id;
// TODO: id lookup table, this is very inefficent
for (const auto& [c_it, id_it] : _cr.view<Contact::Components::ID>().each()) {
for (const auto& [c_it, id_it] : _cs.registry().view<Contact::Components::ID>().each()) {
if (frag_contact_id == id_it.data) {
frag_contact = c_it;
break;
}
}
if (!_cr.valid(frag_contact)) {
if (!_cs.registry().valid(frag_contact)) {
// unkown contact
return false;
}
@ -917,23 +919,23 @@ bool MessageFragmentStore::onEvent(const ObjectStore::Events::ObjectUpdate& e) {
// its also possible it was tagged as empty
e.e.remove<ObjComp::Ephemeral::MessagesEmptyTag>();
Contact3 frag_contact = entt::null;
Contact4 frag_contact = entt::null;
{ // get contact
// probably cached already
if (e.e.all_of<ObjComp::Ephemeral::MessagesContactEntity>()) {
frag_contact = e.e.get<ObjComp::Ephemeral::MessagesContactEntity>().e;
}
if (!_cr.valid(frag_contact)) {
if (!_cs.registry().valid(frag_contact)) {
const auto& frag_contact_id = e.e.get<ObjComp::MessagesContact>().id;
// TODO: id lookup table, this is very inefficent
for (const auto& [c_it, id_it] : _cr.view<Contact::Components::ID>().each()) {
for (const auto& [c_it, id_it] : _cs.registry().view<Contact::Components::ID>().each()) {
if (frag_contact_id == id_it.data) {
frag_contact = c_it;
break;
}
}
if (!_cr.valid(frag_contact)) {
if (!_cs.registry().valid(frag_contact)) {
// unkown contact
return false;
}

View File

@ -12,7 +12,7 @@
#include <entt/container/dense_map.hpp>
#include <entt/container/dense_set.hpp>
#include <solanaceae/contact/contact_model3.hpp>
#include <solanaceae/contact/fwd.hpp>
#include <solanaceae/message3/registry_message_model.hpp>
#include <deque>
@ -50,7 +50,7 @@ class MessageFragmentStore : public RegistryMessageModelEventI, public ObjectSto
static constexpr const char* version {"3"};
protected:
Contact3Registry& _cr;
ContactStore4I& _cs;
RegistryMessageModelI& _rmm;
RegistryMessageModelI::SubscriptionReference _rmm_sr;
ObjectStore2& _os;
@ -78,21 +78,21 @@ class MessageFragmentStore : public RegistryMessageModelEventI, public ObjectSto
struct ECQueueEntry final {
ObjectHandle fid;
Contact3 c;
Contact4 c;
};
std::deque<ECQueueEntry> _event_check_queue;
// range changed or fragment loaded.
// we only load a limited number of fragments at once,
// so we need to keep them dirty until nothing was loaded.
entt::dense_set<Contact3> _potentially_dirty_contacts;
entt::dense_set<Contact4> _potentially_dirty_contacts;
// for cleaning up the ctx vars we create
entt::dense_set<Contact3> _touched_contacts;
entt::dense_set<Contact4> _touched_contacts;
public:
MessageFragmentStore(
Contact3Registry& cr,
ContactStore4I& cr,
RegistryMessageModelI& rmm,
ObjectStore2& os,
StorageBackendIMeta& sbm,