mirror of
https://github.com/matrix-construct/construct
synced 2025-01-01 18:34:18 +01:00
ircd:Ⓜ️ Integrate present room state table optimization into interface.
This commit is contained in:
parent
5b4c65c875
commit
240e01a9b5
2 changed files with 177 additions and 48 deletions
|
@ -178,6 +178,7 @@ struct ircd::m::room::messages
|
|||
struct ircd::m::room::state
|
||||
{
|
||||
struct tuple;
|
||||
struct opts;
|
||||
|
||||
room::id room_id;
|
||||
event::id::buf event_id;
|
||||
|
@ -212,15 +213,24 @@ struct ircd::m::room::state
|
|||
void get(const string_view &type, const string_view &state_key, const event::id::closure &) const;
|
||||
void get(const string_view &type, const string_view &state_key, const event::closure &) const;
|
||||
|
||||
// Refresh the cached root_id/root_id_buf members
|
||||
const m::state::id &refresh();
|
||||
|
||||
state(const m::room &, const opts &);
|
||||
state(const m::room &);
|
||||
state() = default;
|
||||
state(const state &) = delete;
|
||||
state &operator=(const state &) = delete;
|
||||
};
|
||||
|
||||
struct ircd::m::room::state::opts
|
||||
{
|
||||
/// If true, the state btree at the present state becomes the source of the
|
||||
/// data for this interface. This is only significant if no event_id was
|
||||
/// specified in the room object, otherwise snapshot is implied at that
|
||||
/// event. If false (and no event_id was given) the faster sequential
|
||||
/// present state table is used; note that the present state may change
|
||||
/// while you use this object.
|
||||
bool snapshot {false};
|
||||
};
|
||||
|
||||
/// Interface to the members of a room.
|
||||
///
|
||||
/// This interface focuses specifically on room membership and its routines
|
||||
|
|
209
ircd/m/room.cc
209
ircd/m/room.cc
|
@ -328,17 +328,34 @@ ircd::m::room::messages::fetch(std::nothrow_t)
|
|||
//
|
||||
|
||||
ircd::m::room::state::state(const m::room &room)
|
||||
:room_id{room.room_id}
|
||||
,event_id{room.event_id? room.event_id : head(room_id)}
|
||||
:state
|
||||
{
|
||||
room, opts{}
|
||||
}
|
||||
{
|
||||
refresh();
|
||||
}
|
||||
|
||||
const ircd::m::state::id &
|
||||
ircd::m::room::state::refresh()
|
||||
ircd::m::room::state::state(const m::room &room,
|
||||
const opts &opts)
|
||||
:room_id
|
||||
{
|
||||
room.room_id
|
||||
}
|
||||
,event_id
|
||||
{
|
||||
room.event_id?
|
||||
event::id::buf{room.event_id}:
|
||||
opts.snapshot?
|
||||
head(room_id):
|
||||
event::id::buf{}
|
||||
}
|
||||
,root_id
|
||||
{
|
||||
event_id?
|
||||
dbs::state_root(root_id_buf, room_id, event_id):
|
||||
m::state::id{}
|
||||
}
|
||||
{
|
||||
this->root_id = dbs::state_root(root_id_buf, room_id, event_id);
|
||||
return this->root_id;
|
||||
}
|
||||
|
||||
void
|
||||
|
@ -366,11 +383,16 @@ ircd::m::room::state::get(const string_view &type,
|
|||
const event::id::closure &closure)
|
||||
const
|
||||
{
|
||||
m::state::get(root_id, type, state_key, [&closure]
|
||||
(const string_view &event_id)
|
||||
{
|
||||
closure(unquote(event_id));
|
||||
});
|
||||
if(root_id)
|
||||
return m::state::get(root_id, type, state_key, [&closure]
|
||||
(const string_view &event_id)
|
||||
{
|
||||
closure(unquote(event_id));
|
||||
});
|
||||
|
||||
char key[768];
|
||||
auto &column{dbs::room_state};
|
||||
return column(dbs::room_state_key(key, room_id, type, state_key), closure);
|
||||
}
|
||||
|
||||
bool
|
||||
|
@ -400,11 +422,16 @@ ircd::m::room::state::get(std::nothrow_t,
|
|||
const event::id::closure &closure)
|
||||
const
|
||||
{
|
||||
return m::state::get(std::nothrow, root_id, type, state_key, [&closure]
|
||||
(const string_view &event_id)
|
||||
{
|
||||
closure(unquote(event_id));
|
||||
});
|
||||
if(root_id)
|
||||
return m::state::get(std::nothrow, root_id, type, state_key, [&closure]
|
||||
(const string_view &event_id)
|
||||
{
|
||||
closure(unquote(event_id));
|
||||
});
|
||||
|
||||
char key[768];
|
||||
auto &column{dbs::room_state};
|
||||
return column(dbs::room_state_key(key, room_id, type, state_key), std::nothrow, closure);
|
||||
}
|
||||
|
||||
bool
|
||||
|
@ -422,24 +449,53 @@ ircd::m::room::state::has(const string_view &type,
|
|||
const string_view &state_key)
|
||||
const
|
||||
{
|
||||
return m::state::get(std::nothrow, root_id, type, state_key, []
|
||||
(const string_view &event_id)
|
||||
{
|
||||
});
|
||||
if(root_id)
|
||||
return m::state::get(std::nothrow, root_id, type, state_key, []
|
||||
(const string_view &event_id)
|
||||
{});
|
||||
|
||||
char key[768];
|
||||
auto &column{dbs::room_state};
|
||||
return db::has(column, dbs::room_state_key(key, room_id, type, state_key));
|
||||
}
|
||||
|
||||
size_t
|
||||
ircd::m::room::state::count()
|
||||
const
|
||||
{
|
||||
return m::state::count(root_id);
|
||||
if(root_id)
|
||||
return m::state::count(root_id);
|
||||
|
||||
size_t ret{0};
|
||||
auto &column{dbs::room_state};
|
||||
for(auto it{column.begin(room_id)}; bool(it); ++it)
|
||||
++ret;
|
||||
|
||||
return ret;
|
||||
}
|
||||
|
||||
size_t
|
||||
ircd::m::room::state::count(const string_view &type)
|
||||
const
|
||||
{
|
||||
return m::state::count(root_id, type);
|
||||
if(root_id)
|
||||
return m::state::count(root_id, type);
|
||||
|
||||
char keybuf[768];
|
||||
const auto &key
|
||||
{
|
||||
dbs::room_state_key(keybuf, room_id, type)
|
||||
};
|
||||
|
||||
size_t ret{0};
|
||||
auto &column{dbs::room_state};
|
||||
for(auto it{column.begin(key)}; bool(it); ++it)
|
||||
if(std::get<0>(dbs::room_state_key(it->first)) == type)
|
||||
++ret;
|
||||
else
|
||||
break;
|
||||
|
||||
return ret;
|
||||
}
|
||||
|
||||
bool
|
||||
|
@ -462,11 +518,19 @@ bool
|
|||
ircd::m::room::state::test(const event::id::closure_bool &closure)
|
||||
const
|
||||
{
|
||||
return m::state::test(root_id, [&closure]
|
||||
(const json::array &key, const string_view &event_id)
|
||||
{
|
||||
return closure(unquote(event_id));
|
||||
});
|
||||
if(root_id)
|
||||
return m::state::test(root_id, [&closure]
|
||||
(const json::array &key, const string_view &event_id)
|
||||
{
|
||||
return closure(unquote(event_id));
|
||||
});
|
||||
|
||||
auto &column{dbs::room_state};
|
||||
for(auto it{column.begin(room_id)}; bool(it); ++it)
|
||||
if(closure(it->second))
|
||||
return true;
|
||||
|
||||
return false;
|
||||
}
|
||||
|
||||
bool
|
||||
|
@ -491,11 +555,29 @@ ircd::m::room::state::test(const string_view &type,
|
|||
const event::id::closure_bool &closure)
|
||||
const
|
||||
{
|
||||
return m::state::test(root_id, type, [&closure]
|
||||
(const json::array &key, const string_view &event_id)
|
||||
if(root_id)
|
||||
return m::state::test(root_id, type, [&closure]
|
||||
(const json::array &key, const string_view &event_id)
|
||||
{
|
||||
return closure(unquote(event_id));
|
||||
});
|
||||
|
||||
char keybuf[768];
|
||||
const auto &key
|
||||
{
|
||||
return closure(unquote(event_id));
|
||||
});
|
||||
dbs::room_state_key(keybuf, room_id, type)
|
||||
};
|
||||
|
||||
auto &column{dbs::room_state};
|
||||
for(auto it{column.begin(key)}; bool(it); ++it)
|
||||
if(std::get<0>(dbs::room_state_key(it->first)) == type)
|
||||
{
|
||||
if(closure(it->second))
|
||||
return true;
|
||||
}
|
||||
else break;
|
||||
|
||||
return false;
|
||||
}
|
||||
|
||||
bool
|
||||
|
@ -522,11 +604,29 @@ ircd::m::room::state::test(const string_view &type,
|
|||
const event::id::closure_bool &closure)
|
||||
const
|
||||
{
|
||||
return m::state::test(root_id, type, state_key_lb, [&closure]
|
||||
(const json::array &key, const string_view &event_id)
|
||||
if(root_id)
|
||||
return m::state::test(root_id, type, state_key_lb, [&closure]
|
||||
(const json::array &key, const string_view &event_id)
|
||||
{
|
||||
return closure(unquote(event_id));
|
||||
});
|
||||
|
||||
char keybuf[768];
|
||||
const auto &key
|
||||
{
|
||||
return closure(unquote(event_id));
|
||||
});
|
||||
dbs::room_state_key(keybuf, room_id, type, state_key_lb)
|
||||
};
|
||||
|
||||
auto &column{dbs::room_state};
|
||||
for(auto it{column.begin(key)}; bool(it); ++it)
|
||||
if(std::get<0>(dbs::room_state_key(it->first)) == type)
|
||||
{
|
||||
if(closure(it->second))
|
||||
return true;
|
||||
}
|
||||
else break;
|
||||
|
||||
return false;
|
||||
}
|
||||
|
||||
void
|
||||
|
@ -546,11 +646,16 @@ void
|
|||
ircd::m::room::state::for_each(const event::id::closure &closure)
|
||||
const
|
||||
{
|
||||
m::state::for_each(root_id, [&closure]
|
||||
(const json::array &key, const string_view &event_id)
|
||||
{
|
||||
closure(unquote(event_id));
|
||||
});
|
||||
if(root_id)
|
||||
return m::state::for_each(root_id, [&closure]
|
||||
(const json::array &key, const string_view &event_id)
|
||||
{
|
||||
closure(unquote(event_id));
|
||||
});
|
||||
|
||||
auto &column{dbs::room_state};
|
||||
for(auto it{column.begin(room_id)}; bool(it); ++it)
|
||||
closure(it->second);
|
||||
}
|
||||
|
||||
void
|
||||
|
@ -572,11 +677,25 @@ ircd::m::room::state::for_each(const string_view &type,
|
|||
const event::id::closure &closure)
|
||||
const
|
||||
{
|
||||
m::state::for_each(root_id, type, [&closure]
|
||||
(const json::array &key, const string_view &event_id)
|
||||
if(root_id)
|
||||
return m::state::for_each(root_id, type, [&closure]
|
||||
(const json::array &key, const string_view &event_id)
|
||||
{
|
||||
closure(unquote(event_id));
|
||||
});
|
||||
|
||||
char keybuf[768];
|
||||
const auto &key
|
||||
{
|
||||
closure(unquote(event_id));
|
||||
});
|
||||
dbs::room_state_key(keybuf, room_id, type)
|
||||
};
|
||||
|
||||
auto &column{dbs::room_state};
|
||||
for(auto it{column.begin(key)}; bool(it); ++it)
|
||||
if(std::get<0>(dbs::room_state_key(it->first)) == type)
|
||||
closure(it->second);
|
||||
else
|
||||
break;
|
||||
}
|
||||
|
||||
//
|
||||
|
|
Loading…
Reference in a new issue