0
0
Fork 0
mirror of https://github.com/matrix-construct/construct synced 2024-12-27 07:54:05 +01:00

modules/console: Add cmd to display amount of a room's state in cache.

This commit is contained in:
Jason Volk 2018-12-03 17:35:16 -08:00
parent 2a2a8bcf86
commit c75ccd5a1c

View file

@ -6621,6 +6621,81 @@ console_cmd__room__state__prefetch(opt &out, const string_view &line)
return true;
}
bool
console_cmd__room__state__cache(opt &out, const string_view &line)
{
const params param{line, " ",
{
"room_id", "[event_id_or_type]", "[type]"
}};
const auto &room_id
{
m::room_id(param.at("room_id"))
};
const auto &event_id_or_type
{
param.at("[event_id_or_type]", string_view{})
};
const auto is_event_id
{
m::has_sigil(event_id_or_type) && valid(m::id::EVENT, event_id_or_type)
};
const string_view &event_id
{
is_event_id?
event_id_or_type:
string_view{}
};
const auto &type
{
is_event_id?
param.at("[type]", string_view{}):
event_id_or_type
};
const m::room room
{
room_id, event_id
};
const m::room::state state
{
room
};
size_t total(0);
std::array<size_t, m::dbs::event_columns> res {{0}};
state.for_each(type, m::event::closure_idx{[&total, &res]
(const m::event::idx &event_idx)
{
const byte_view<string_view> &key(event_idx);
for(size_t i(0); i < m::dbs::event_column.size(); ++i)
{
const auto &column(m::dbs::event_column[i]);
res[i] += db::exists(db::cache(column), key);
}
++total;
}});
std::array<string_view, m::event::size()> keys;
_key_transform(m::event{}, begin(keys), end(keys));
assert(res.size() == keys.size());
for(size_t i(0); i < keys.size(); ++i)
out << std::left << std::setw(16) << keys[i]
<< " " << std::right << std::setw(6) << res[i]
<< " of " << std::left << std::setw(6) << total
<< std::endl;
return true;
}
bool
console_cmd__room__count(opt &out, const string_view &line)
{