0
0
Fork 0
mirror of https://github.com/matrix-construct/construct synced 2024-06-16 08:58:20 +02:00

ircd:Ⓜ️:room::messages: Simplify/optimize seek() functions.

This commit is contained in:
Jason Volk 2019-02-04 18:10:23 -08:00
parent d5f01d013d
commit 7e11176ab7
2 changed files with 9 additions and 18 deletions

View file

@ -49,9 +49,8 @@ struct ircd::m::room::messages
const m::event &fetch();
bool seek_idx(const event::idx &);
bool seek(const uint64_t &depth);
bool seek(const uint64_t &depth = -1);
bool seek(const event::id &);
bool seek();
// These are reversed on purpose
auto &operator++() { return --it; }

View file

@ -683,36 +683,28 @@ ircd::m::room::messages::operator*()
return fetch(std::nothrow);
};
bool
ircd::m::room::messages::seek()
{
this->it = dbs::room_events.begin(room.room_id);
return bool(*this);
}
bool
ircd::m::room::messages::seek(const event::id &event_id)
try
{
const event::idx &event_idx
{
index(event_id)
index(event_id, std::nothrow)
};
return seek_idx(event_idx);
}
catch(const db::not_found &e)
{
return false;
return event_idx?
seek_idx(event_idx):
false;
}
bool
ircd::m::room::messages::seek(const uint64_t &depth)
{
char buf[dbs::ROOM_EVENTS_KEY_MAX_SIZE];
const auto seek_key
const string_view seek_key
{
dbs::room_events_key(buf, room.room_id, depth)
depth != uint64_t(-1)?
dbs::room_events_key(buf, room.room_id, depth):
room.room_id
};
this->it = dbs::room_events.begin(seek_key);