0
0
Fork 0
mirror of https://github.com/matrix-construct/construct synced 2024-11-29 10:12:39 +01:00

ircd: Use bool return values through prefetching stack.

This commit is contained in:
Jason Volk 2019-08-19 21:17:42 -07:00
parent 7c6a0be4b5
commit ac03c9a13b
5 changed files with 36 additions and 20 deletions

View file

@ -42,7 +42,7 @@ namespace ircd::db
// [GET] Tests if key exists // [GET] Tests if key exists
bool has(column &, const string_view &key, const gopts & = {}); bool has(column &, const string_view &key, const gopts & = {});
bool cached(column &, const string_view &key, const gopts & = {}); bool cached(column &, const string_view &key, const gopts & = {});
void prefetch(column &, const string_view &key, const gopts & = {}); bool prefetch(column &, const string_view &key, const gopts & = {});
// [GET] Query space usage // [GET] Query space usage
size_t bytes(column &, const std::pair<string_view, string_view> &range, const gopts & = {}); size_t bytes(column &, const std::pair<string_view, string_view> &range, const gopts & = {});

View file

@ -13,9 +13,9 @@
namespace ircd::m namespace ircd::m
{ {
void prefetch(const event::idx &, const event::fetch::opts & = event::fetch::default_opts); bool prefetch(const event::idx &, const event::fetch::opts & = event::fetch::default_opts);
void prefetch(const event::idx &, const string_view &key); bool prefetch(const event::idx &, const string_view &key);
void prefetch(const event::id &, const event::fetch::opts & = event::fetch::default_opts); bool prefetch(const event::id &, const event::fetch::opts & = event::fetch::default_opts);
void prefetch(const event::id &, const string_view &key); bool prefetch(const event::id &, const string_view &key);
} }

View file

@ -5784,22 +5784,25 @@ ircd::db::bytes(column &column,
return ret[0]; return ret[0];
} }
void bool
ircd::db::prefetch(column &column, ircd::db::prefetch(column &column,
const string_view &key, const string_view &key,
const gopts &gopts) const gopts &gopts)
{ {
if(cached(column, key, gopts)) if(cached(column, key, gopts))
return; return false;
if(!request.avail()) if(!request.avail())
return; return false;
request([column(column), key(std::string(key)), gopts] request([column(column), key(std::string(key)), gopts]
() mutable () mutable
{ {
has(column, key, gopts); has(column, key, gopts);
}); });
ctx::yield();
return true;
} }
#if 0 #if 0

View file

@ -789,32 +789,46 @@ const
// event/prefetch.h // event/prefetch.h
// //
void bool
ircd::m::prefetch(const event::id &event_id, ircd::m::prefetch(const event::id &event_id,
const event::fetch::opts &opts) const event::fetch::opts &opts)
{ {
prefetch(index(event_id), opts); return prefetch(index(event_id), opts);
} }
void bool
ircd::m::prefetch(const event::id &event_id, ircd::m::prefetch(const event::id &event_id,
const string_view &key) const string_view &key)
{ {
prefetch(index(event_id), key); return prefetch(index(event_id), key);
} }
void bool
ircd::m::prefetch(const event::idx &event_idx, ircd::m::prefetch(const event::idx &event_idx,
const event::fetch::opts &opts) const event::fetch::opts &opts)
{ {
const event::keys keys{opts.keys}; if(event::fetch::should_seek_json(opts))
const vector_view<const string_view> cols{keys}; return db::prefetch(dbs::event_json, byte_view<string_view>{event_idx});
const event::keys keys
{
opts.keys
};
const vector_view<const string_view> cols
{
keys
};
bool ret{false};
for(const auto &col : cols) for(const auto &col : cols)
if(col) if(col)
prefetch(event_idx, col); ret |= prefetch(event_idx, col);
return ret;
} }
void bool
ircd::m::prefetch(const event::idx &event_idx, ircd::m::prefetch(const event::idx &event_idx,
const string_view &key) const string_view &key)
{ {
@ -828,7 +842,7 @@ ircd::m::prefetch(const event::idx &event_idx,
dbs::event_column.at(column_idx) dbs::event_column.at(column_idx)
}; };
db::prefetch(column, byte_view<string_view>{event_idx}); return db::prefetch(column, byte_view<string_view>{event_idx});
} }
/////////////////////////////////////////////////////////////////////////////// ///////////////////////////////////////////////////////////////////////////////

View file

@ -192,8 +192,7 @@ ircd::m::room::state::prefetch(const state &state,
if(range.second && event_idx > range.second) if(range.second && event_idx > range.second)
return; return;
m::prefetch(event_idx, fopts); ret += m::prefetch(event_idx, fopts);
++ret;
}}); }});
return ret; return ret;