mirror of
https://github.com/matrix-construct/construct
synced 2025-02-18 17:50:16 +01:00
ircd:Ⓜ️:event::fetch: Simplify interface; reference opts as class member.
This commit is contained in:
parent
e20d71a28a
commit
5ce55a9dee
3 changed files with 36 additions and 43 deletions
|
@ -39,6 +39,7 @@ struct ircd::m::event::fetch
|
|||
|
||||
static const opts default_opts;
|
||||
|
||||
const opts *fopts {&default_opts};
|
||||
std::array<db::cell, event::size()> cell;
|
||||
db::cell _json;
|
||||
db::row row;
|
||||
|
@ -46,8 +47,8 @@ struct ircd::m::event::fetch
|
|||
|
||||
static string_view key(const event::idx *const &);
|
||||
static bool should_seek_json(const opts &);
|
||||
bool assign_from_json(const opts &);
|
||||
bool assign_from_row(const opts &, const string_view &key);
|
||||
bool assign_from_row(const string_view &key);
|
||||
bool assign_from_json();
|
||||
|
||||
public:
|
||||
fetch(const idx &, std::nothrow_t, const opts & = default_opts);
|
||||
|
@ -66,11 +67,11 @@ struct ircd::m::event::fetch
|
|||
|
||||
namespace ircd::m
|
||||
{
|
||||
bool seek(event::fetch &, const event::idx &, std::nothrow_t, const event::fetch::opts & = event::fetch::default_opts);
|
||||
void seek(event::fetch &, const event::idx &, const event::fetch::opts & = event::fetch::default_opts);
|
||||
bool seek(event::fetch &, const event::idx &, std::nothrow_t);
|
||||
void seek(event::fetch &, const event::idx &);
|
||||
|
||||
bool seek(event::fetch &, const event::id &, std::nothrow_t, const event::fetch::opts & = event::fetch::default_opts);
|
||||
void seek(event::fetch &, const event::id &, const event::fetch::opts & = event::fetch::default_opts);
|
||||
bool seek(event::fetch &, const event::id &, std::nothrow_t);
|
||||
void seek(event::fetch &, const event::id &);
|
||||
}
|
||||
|
||||
/// Event Fetch Options.
|
||||
|
|
|
@ -1293,10 +1293,9 @@ ircd::m::index(const event::id &event_id,
|
|||
|
||||
void
|
||||
ircd::m::seek(event::fetch &fetch,
|
||||
const event::id &event_id,
|
||||
const event::fetch::opts &opts)
|
||||
const event::id &event_id)
|
||||
{
|
||||
if(!seek(fetch, event_id, std::nothrow, opts))
|
||||
if(!seek(fetch, event_id, std::nothrow))
|
||||
throw m::NOT_FOUND
|
||||
{
|
||||
"%s not found in database", event_id
|
||||
|
@ -1306,8 +1305,7 @@ ircd::m::seek(event::fetch &fetch,
|
|||
bool
|
||||
ircd::m::seek(event::fetch &fetch,
|
||||
const event::id &event_id,
|
||||
std::nothrow_t,
|
||||
const event::fetch::opts &opts)
|
||||
std::nothrow_t)
|
||||
{
|
||||
const auto &event_idx
|
||||
{
|
||||
|
@ -1320,15 +1318,14 @@ ircd::m::seek(event::fetch &fetch,
|
|||
return fetch.valid;
|
||||
}
|
||||
|
||||
return seek(fetch, event_idx, std::nothrow, opts);
|
||||
return seek(fetch, event_idx, std::nothrow);
|
||||
}
|
||||
|
||||
void
|
||||
ircd::m::seek(event::fetch &fetch,
|
||||
const event::idx &event_idx,
|
||||
const event::fetch::opts &opts)
|
||||
const event::idx &event_idx)
|
||||
{
|
||||
if(!seek(fetch, event_idx, std::nothrow, opts))
|
||||
if(!seek(fetch, event_idx, std::nothrow))
|
||||
throw m::NOT_FOUND
|
||||
{
|
||||
"%lu not found in database", event_idx
|
||||
|
@ -1338,8 +1335,7 @@ ircd::m::seek(event::fetch &fetch,
|
|||
bool
|
||||
ircd::m::seek(event::fetch &fetch,
|
||||
const event::idx &event_idx,
|
||||
std::nothrow_t,
|
||||
const event::fetch::opts &opts)
|
||||
std::nothrow_t)
|
||||
{
|
||||
auto &event
|
||||
{
|
||||
|
@ -1351,12 +1347,14 @@ ircd::m::seek(event::fetch &fetch,
|
|||
byte_view<string_view>(event_idx)
|
||||
};
|
||||
|
||||
assert(fetch.fopts);
|
||||
const auto &opts(*fetch.fopts);
|
||||
if(fetch.should_seek_json(opts))
|
||||
if((fetch.valid = fetch._json.load(key, opts.gopts)))
|
||||
return fetch.assign_from_json(opts);
|
||||
return fetch.assign_from_json();
|
||||
|
||||
if((fetch.valid = db::seek(fetch.row, key, opts.gopts)))
|
||||
fetch.valid = fetch.assign_from_row(opts, key);
|
||||
fetch.valid = fetch.assign_from_row(key);
|
||||
|
||||
return fetch.valid;
|
||||
}
|
||||
|
@ -1437,9 +1435,13 @@ ircd::m::event::fetch::fetch(const event::idx &event_idx,
|
|||
std::nothrow_t,
|
||||
const opts &opts)
|
||||
:event{}
|
||||
,fopts
|
||||
{
|
||||
&opts
|
||||
}
|
||||
,_json
|
||||
{
|
||||
m::dbs::event_json,
|
||||
dbs::event_json,
|
||||
event_idx && should_seek_json(opts)?
|
||||
key(&event_idx):
|
||||
string_view{},
|
||||
|
@ -1460,8 +1462,8 @@ ircd::m::event::fetch::fetch(const event::idx &event_idx,
|
|||
,valid
|
||||
{
|
||||
event_idx && _json.valid(key(&event_idx))?
|
||||
assign_from_json(opts):
|
||||
assign_from_row(opts, key(&event_idx))
|
||||
assign_from_json():
|
||||
assign_from_row(key(&event_idx))
|
||||
}
|
||||
{
|
||||
}
|
||||
|
@ -1469,9 +1471,13 @@ ircd::m::event::fetch::fetch(const event::idx &event_idx,
|
|||
/// Seekless constructor.
|
||||
ircd::m::event::fetch::fetch(const opts &opts)
|
||||
:event{}
|
||||
,fopts
|
||||
{
|
||||
&opts
|
||||
}
|
||||
,_json
|
||||
{
|
||||
m::dbs::event_json,
|
||||
dbs::event_json,
|
||||
string_view{},
|
||||
opts.gopts
|
||||
}
|
||||
|
@ -1493,7 +1499,7 @@ ircd::m::event::fetch::fetch(const opts &opts)
|
|||
}
|
||||
|
||||
bool
|
||||
ircd::m::event::fetch::assign_from_json(const opts &opts)
|
||||
ircd::m::event::fetch::assign_from_json()
|
||||
{
|
||||
auto &event
|
||||
{
|
||||
|
@ -1505,9 +1511,10 @@ ircd::m::event::fetch::assign_from_json(const opts &opts)
|
|||
_json.val()
|
||||
};
|
||||
|
||||
assert(fopts);
|
||||
event =
|
||||
{
|
||||
source, opts.keys
|
||||
source, fopts->keys
|
||||
};
|
||||
|
||||
assert(!empty(source));
|
||||
|
@ -1516,8 +1523,7 @@ ircd::m::event::fetch::assign_from_json(const opts &opts)
|
|||
}
|
||||
|
||||
bool
|
||||
ircd::m::event::fetch::assign_from_row(const opts &opts,
|
||||
const string_view &key)
|
||||
ircd::m::event::fetch::assign_from_row(const string_view &key)
|
||||
{
|
||||
auto &event
|
||||
{
|
||||
|
|
|
@ -802,28 +802,14 @@ const
|
|||
const ircd::m::event &
|
||||
ircd::m::room::messages::fetch()
|
||||
{
|
||||
const event::fetch::opts &fopts
|
||||
{
|
||||
room.fopts?
|
||||
*room.fopts:
|
||||
event::fetch::default_opts
|
||||
};
|
||||
|
||||
m::seek(_event, event_idx(), fopts);
|
||||
m::seek(_event, event_idx());
|
||||
return _event;
|
||||
}
|
||||
|
||||
const ircd::m::event &
|
||||
ircd::m::room::messages::fetch(std::nothrow_t)
|
||||
{
|
||||
const event::fetch::opts &fopts
|
||||
{
|
||||
room.fopts?
|
||||
*room.fopts:
|
||||
event::fetch::default_opts
|
||||
};
|
||||
|
||||
m::seek(_event, event_idx(), std::nothrow, fopts);
|
||||
m::seek(_event, event_idx(), std::nothrow);
|
||||
return _event;
|
||||
}
|
||||
|
||||
|
|
Loading…
Add table
Reference in a new issue