diff --git a/include/ircd/m/room.h b/include/ircd/m/room.h index 924c80095..861040705 100644 --- a/include/ircd/m/room.h +++ b/include/ircd/m/room.h @@ -96,8 +96,8 @@ struct ircd::m::room // observer misc bool membership(const m::id::user &, const string_view &membership = "join") const; - uint64_t maxdepth(event::id::buf &) const; - uint64_t maxdepth() const; + int64_t maxdepth(event::id::buf &) const; + int64_t maxdepth() const; // modify room(const alias &, const event::id &event_id = {}); diff --git a/ircd/m/room.cc b/ircd/m/room.cc index e31aa1789..e61657308 100644 --- a/ircd/m/room.cc +++ b/ircd/m/room.cc @@ -409,8 +409,7 @@ const return m::vm::test(query, closure); } -/// academic search -uint64_t +int64_t ircd::m::room::maxdepth() const { @@ -418,28 +417,22 @@ const return maxdepth(buf); } -/// academic search -uint64_t +int64_t ircd::m::room::maxdepth(event::id::buf &buf) const { - const vm::query query + const auto it { - { "room_id", room_id }, + dbs::room_events.begin(room_id) }; - int64_t depth{0}; - vm::for_each(query, [&buf, &depth] - (const auto &event) - { - if(json::get<"depth"_>(event) > depth) - { - depth = json::get<"depth"_>(event); - buf = json::get<"event_id"_>(event); - } - }); + if(!it) + return -1; - return depth; + const auto &key(it->first); + const auto parts{dbs::room_events_key(key)}; + buf = std::get<1>(parts); + return std::get<0>(parts); } //