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

ircd:Ⓜ️:vm: Add an opts.unique bypass option for condition.

This commit is contained in:
Jason Volk 2020-03-17 11:21:27 -07:00
parent b8c31fe4d3
commit 0b8b3ee988
3 changed files with 16 additions and 11 deletions

View file

@ -243,6 +243,11 @@ struct ircd::m::vm::opts
/// replayed through the system (not recommended).
bool replays {false};
/// Bypass check for another evaluation of the same event_id already
/// occurring. If this is false (not recommended) two duplicate events
/// being evaluated may race through the core.
bool unique {true};
/// If the input event has a reference to already-strung json we can use
/// that directly when writing to the DB. When this is false we will
/// re-stringify the event internally either from a referenced source or

View file

@ -329,10 +329,11 @@ ircd::m::vm::eval::operator()(const vector_view<m::event> &events)
// evaluation is finished. If the other was successful, the exists()
// check will skip this, otherwise we have to try again here because
// this evaluator might be using different options/credentials.
sequence::dock.wait([&event]
{
return eval::count(event.event_id) == 0;
});
if(likely(opts->unique))
sequence::dock.wait([&event]
{
return eval::count(event.event_id) == 0;
});
if(likely(!opts->replays) && m::exists(event.event_id))
continue;

View file

@ -436,14 +436,13 @@ ircd::m::vm::execute_pdu(eval &eval,
// Wait for any pending duplicate evals before proceeding.
assert(eval::count(event_id));
sequence::dock.wait([&event_id]
{
return eval::count(event_id) <= 1;
});
if(likely(opts.unique))
sequence::dock.wait([&event_id]
{
return eval::count(event_id) <= 1;
});
// This branch won't be taken anymore with the above condition added; but
// leaving the code for reference right now.
if((false) && unlikely(eval::count(event_id) > 1))
if(likely(opts.unique) && unlikely(eval::count(event_id) > 1))
throw error
{
fault::EXISTS, "Event is already being evaluated."