0
0
Fork 0
mirror of https://github.com/matrix-construct/construct synced 2024-09-30 04:38:52 +02:00

modules/vm: Simplify head fetch before write commit.

This commit is contained in:
Jason Volk 2018-10-31 11:54:16 -07:00
parent 73c85c14e1
commit 7b307e6151

View file

@ -701,18 +701,35 @@ ircd::m::vm::_eval_pdu(eval &eval,
return fault::ACCEPT;
}
int64_t top;
id::event::buf head;
std::tie(head, top, std::ignore) = m::top(std::nothrow, room_id);
if(top < 0 && (opts.head_must_exist || opts.history))
const bool require_head
{
opts.head_must_exist || opts.history
};
const id::event::buf head
{
require_head?
m::head(std::nothrow, room_id):
id::event::buf{}
};
if(unlikely(require_head && !head))
throw error
{
fault::STATE, "Found nothing for room %s",
fault::STATE, "Required head for room %s not found.",
string_view{room_id}
};
m::room room{room_id, head};
m::room::state state{room};
const m::room room
{
room_id, head
};
const m::room::state state
{
room
};
wopts.root_in = state.root_id;
dbs::write(txn, event, wopts);
write_commit(eval);