0
0
Fork 0
mirror of https://github.com/matrix-construct/construct synced 2024-11-04 21:08:57 +01:00

ircd:Ⓜ️:room::events: Cleanup/simplify; reorg interface.

This commit is contained in:
Jason Volk 2019-09-24 14:26:29 -07:00
parent 5d9ec170f8
commit 9cb0f46440
2 changed files with 52 additions and 58 deletions

View file

@ -62,28 +62,29 @@ struct ircd::m::room::events
explicit operator bool() const { return bool(it); } explicit operator bool() const { return bool(it); }
bool operator!() const { return !it; } bool operator!() const { return !it; }
event::id::buf event_id() const; // deprecated; will remove // Observers from the current valid iterator
event::idx event_idx() const; // Available from the iterator key. uint64_t depth() const;
uint64_t depth() const; // Available from the iterator key. event::idx event_idx() const;
explicit operator event::idx() const; explicit operator event::idx() const;
const m::event &fetch(std::nothrow_t); // Perform a new lookup / iterator
const m::event &fetch();
bool prefetch(const string_view &event_prop);
bool prefetch(); // uses property keys from any fetch::opts supplied.
bool seek_idx(const event::idx &); bool seek_idx(const event::idx &);
bool seek(const uint64_t &depth = -1); bool seek(const uint64_t &depth = -1);
bool seek(const event::id &); bool seek(const event::id &);
// These are reversed on purpose // Move the iterator
auto &operator++() { return --it; } auto &operator++() { return --it; }
auto &operator--() { return ++it; } auto &operator--() { return ++it; }
// Fetch the actual event data at the iterator's position
const m::event &operator*(); const m::event &operator*();
const m::event *operator->() { return &operator*(); } const m::event *operator->() { return &operator*(); }
const m::event &fetch(std::nothrow_t);
const m::event &fetch();
// Prefetch the actual event data at the iterator's position
bool prefetch(const string_view &event_prop);
bool prefetch(); // uses supplied fetch::opts.
events(const m::room &, events(const m::room &,
const uint64_t &depth, const uint64_t &depth,

View file

@ -1669,6 +1669,33 @@ ircd::m::room::events::events(const m::room &room,
seek(1); seek(1);
} }
bool
ircd::m::room::events::prefetch()
{
assert(_event.fopts);
return m::prefetch(event_idx(), *_event.fopts);
}
bool
ircd::m::room::events::prefetch(const string_view &event_prop)
{
return m::prefetch(event_idx(), event_prop);
}
const ircd::m::event &
ircd::m::room::events::fetch()
{
m::seek(_event, event_idx());
return _event;
}
const ircd::m::event &
ircd::m::room::events::fetch(std::nothrow_t)
{
m::seek(_event, event_idx(), std::nothrow);
return _event;
}
const ircd::m::event & const ircd::m::event &
ircd::m::room::events::operator*() ircd::m::room::events::operator*()
{ {
@ -1735,33 +1762,6 @@ catch(const db::not_found &e)
return false; return false;
} }
bool
ircd::m::room::events::prefetch()
{
assert(_event.fopts);
return m::prefetch(event_idx(), *_event.fopts);
}
bool
ircd::m::room::events::prefetch(const string_view &event_prop)
{
return m::prefetch(event_idx(), event_prop);
}
const ircd::m::event &
ircd::m::room::events::fetch()
{
m::seek(_event, event_idx());
return _event;
}
const ircd::m::event &
ircd::m::room::events::fetch(std::nothrow_t)
{
m::seek(_event, event_idx(), std::nothrow);
return _event;
}
ircd::m::room::events::operator ircd::m::room::events::operator
ircd::m::event::idx() ircd::m::event::idx()
const const
@ -1769,26 +1769,6 @@ const
return event_idx(); return event_idx();
} }
ircd::m::event::id::buf
ircd::m::room::events::event_id()
const
{
return m::event_id(this->event_idx(), std::nothrow);
}
uint64_t
ircd::m::room::events::depth()
const
{
assert(bool(*this));
const auto part
{
dbs::room_events_key(it->first)
};
return std::get<0>(part);
}
ircd::m::event::idx ircd::m::event::idx
ircd::m::room::events::event_idx() ircd::m::room::events::event_idx()
const const
@ -1802,6 +1782,19 @@ const
return std::get<1>(part); return std::get<1>(part);
} }
uint64_t
ircd::m::room::events::depth()
const
{
assert(bool(*this));
const auto part
{
dbs::room_events_key(it->first)
};
return std::get<0>(part);
}
// //
// room::state // room::state
// //