From 26ca956e5b7af76473ffeec4f3fc3682bbe6daea Mon Sep 17 00:00:00 2001 From: Jason Volk Date: Mon, 2 Nov 2020 15:19:54 -0800 Subject: [PATCH] modules/console: Add room missing/horizon count cmds; add limit param. --- modules/console.cc | 111 ++++++++++++++++++++++++++++++++++++--------- 1 file changed, 89 insertions(+), 22 deletions(-) diff --git a/modules/console.cc b/modules/console.cc index fe2c7a326..358ddcd53 100644 --- a/modules/console.cc +++ b/modules/console.cc @@ -10748,17 +10748,11 @@ console_cmd__room__events__missing(opt &out, const string_view &line) (const auto &event_id, const auto &ref_depth, const auto &ref_idx) { out - << std::right - << std::setw(10) - << ref_idx + << std::right << std::setw(10) << ref_idx << " " - << std::right - << std::setw(8) - << ref_depth + << std::right << std::setw(8) << ref_depth << " " - << std::left - << std::setw(52) - << event_id + << std::left << std::setw(52) << event_id << std::endl; return --limit; }); @@ -10766,12 +10760,54 @@ console_cmd__room__events__missing(opt &out, const string_view &line) return true; } +bool +console_cmd__room__events__missing__count(opt &out, const string_view &line) +{ + const params param{line, " ", + { + "room_id", "limit", "min_depth", "event_id" + }}; + + const auto &room_id + { + m::room_id(param.at("room_id")) + }; + + auto limit + { + param.at("limit", 16L) + }; + + const auto &min_depth + { + param.at("min_depth", 0L) + }; + + const auto &event_id + { + param["event_id"] + }; + + const m::room room + { + room_id, event_id + }; + + const m::room::events::missing missing + { + room + }; + + out << missing.count() << std::endl; + return true; +} + bool console_cmd__room__events__horizon(opt &out, const string_view &line) { const params param{line, " ", { - "room_id" + "room_id", "event_id", "limit" }}; const auto &room_id @@ -10781,7 +10817,12 @@ console_cmd__room__events__horizon(opt &out, const string_view &line) const auto &event_id { - param[2] + param.at("event_id", "*"_sv) + }; + + auto limit + { + param.at("limit", 32L) }; const m::room room @@ -10794,28 +10835,54 @@ console_cmd__room__events__horizon(opt &out, const string_view &line) room }; - horizon.for_each([&out] + horizon.for_each([&out, &limit] (const auto &event_id, const auto &ref_depth, const auto &ref_idx) { out - << std::right - << std::setw(10) - << ref_idx + << std::right << std::setw(10) << ref_idx << " " - << std::right - << std::setw(8) - << ref_depth + << std::right << std::setw(8) << ref_depth << " " - << std::left - << std::setw(52) - << event_id + << std::left << std::setw(52) << event_id << std::endl; - return true; + return --limit; }); return true; } +bool +console_cmd__room__events__horizon__count(opt &out, const string_view &line) +{ + const params param{line, " ", + { + "room_id", "event_id" + }}; + + const auto &room_id + { + m::room_id(param.at("room_id")) + }; + + const auto &event_id + { + param.at("event_id", "*"_sv) + }; + + const m::room room + { + room_id, event_id + }; + + const m::room::events::horizon horizon + { + room + }; + + out << horizon.count() << std::endl; + return true; +} + bool console_cmd__room__events__horizon__rebuild(opt &out, const string_view &line) {