diff --git a/modules/console.cc b/modules/console.cc index c1844cb7b..de6dbefa9 100644 --- a/modules/console.cc +++ b/modules/console.cc @@ -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 res {{0}}; + state.for_each(type, m::event::closure_idx{[&total, &res] + (const m::event::idx &event_idx) + { + const byte_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 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) {