0
0
Fork 0
mirror of https://github.com/matrix-construct/construct synced 2024-11-25 16:22:35 +01:00

ircd:Ⓜ️:room: Finesse a messages::seek_idx() into the seek stack.

This commit is contained in:
Jason Volk 2018-09-07 06:19:21 -07:00
parent 7dd0d3b522
commit 632278e607
2 changed files with 34 additions and 21 deletions

View file

@ -196,6 +196,7 @@ struct ircd::m::room::messages
const m::event &fetch(std::nothrow_t);
const m::event &fetch();
bool seek_idx(const event::idx &);
bool seek(const uint64_t &depth);
bool seek(const event::id &);
bool seek();

View file

@ -553,31 +553,12 @@ bool
ircd::m::room::messages::seek(const event::id &event_id)
try
{
auto &column
{
dbs::event_column.at(json::indexof<event, "depth"_>())
};
const event::idx event_idx
const event::idx &event_idx
{
index(event_id)
};
uint64_t depth;
column(byte_view<string_view>(event_idx), [&depth]
(const string_view &value)
{
depth = byte_view<uint64_t>(value);
});
char buf[dbs::ROOM_EVENTS_KEY_MAX_SIZE];
const auto seek_key
{
dbs::room_events_key(buf, room.room_id, depth, event_idx)
};
this->it = dbs::room_events.begin(seek_key);
return bool(*this);
return seek_idx(event_idx);
}
catch(const db::not_found &e)
{
@ -597,6 +578,37 @@ ircd::m::room::messages::seek(const uint64_t &depth)
return bool(*this);
}
bool
ircd::m::room::messages::seek_idx(const event::idx &event_idx)
try
{
uint64_t depth;
m::get(event_idx, "depth", mutable_buffer
{
reinterpret_cast<char *>(&depth), sizeof(depth)
});
char buf[dbs::ROOM_EVENTS_KEY_MAX_SIZE];
const auto &seek_key
{
dbs::room_events_key(buf, room.room_id, depth, event_idx)
};
this->it = dbs::room_events.begin(seek_key);
if(!bool(*this))
return false;
// Check if this event_idx is actually in this room
if(event_idx != this->event_idx())
return false;
return true;
}
catch(const db::not_found &e)
{
return false;
}
ircd::m::event::id::buf
ircd::m::room::messages::event_id()
{