mirror of
https://github.com/matrix-construct/construct
synced 2024-11-29 10:12:39 +01:00
ircd:Ⓜ️ Reenable the room::maxdepth() query with efficiency.
This commit is contained in:
parent
2db910adea
commit
fd7792d32b
2 changed files with 12 additions and 19 deletions
|
@ -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 = {});
|
||||
|
|
|
@ -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<vm::where::equal> 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);
|
||||
}
|
||||
|
||||
//
|
||||
|
|
Loading…
Reference in a new issue