0
0
Fork 0
mirror of https://github.com/matrix-construct/construct synced 2024-06-09 05:29:00 +02:00

ircd:Ⓜ️:vm: Add options over existing state fetch decisions.

This commit is contained in:
Jason Volk 2020-11-20 13:46:37 -08:00
parent ebe958d574
commit b897071ce3
2 changed files with 38 additions and 8 deletions

View file

@ -302,6 +302,18 @@ struct ircd::m::vm::opts
/// are missing. -1 is auto / conf.
size_t fetch_prev_limit = -1;
/// Considers any missing prev_event as an indication of possible missing
/// state from a history we don't have; allowing a state acquisition. This
/// is not practical to apply by default as internal decisions are better.
bool fetch_state_any {false};
/// This option affects the behavior for a case where we are missing the
/// (depth - 1) prev_events reference, thus other resolved references
/// are not adjacent. Yet at the claimed depth there is no apparent gap
/// in the timeline. If true, we assume possible missing state in this
/// case, but by default that is far too unrealistic in practice.
bool fetch_state_shallow {false};
/// Evaluators can set this value to optimize the creation of the database
/// transaction where the event will be stored. This value should be set
/// to the amount of space the event consumes; the JSON-serialized size is

View file

@ -381,17 +381,35 @@ ircd::m::vm::fetch::state(const event &event,
const room &room)
try
{
const event::prev prev{event};
if(prev.prev_exist())
return;
const auto &[sounding_depth, sounding_idx]
const auto &opts{*eval.opts};
const event::prev prev
{
m::sounding(room.room_id)
event
};
if(at<"depth"_>(event) > sounding_depth)
return;
const bool prev_exist
{
prev.prev_exist()
};
if(opts.fetch_state_any)
if(prev_exist && prev.prev_events_count() == prev.prev_events_exist())
return;
if(likely(!opts.fetch_state_any))
if(prev_exist)
return;
if(likely(!opts.fetch_state_shallow))
{
const auto &[sounding_depth, sounding_idx]
{
m::sounding(room.room_id)
};
if(at<"depth"_>(event) > sounding_depth)
return;
}
log::dwarning
{