0
0
Fork 0
mirror of https://github.com/matrix-construct/construct synced 2024-11-17 23:40:57 +01: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; return fault::ACCEPT;
} }
int64_t top; const bool require_head
id::event::buf head; {
std::tie(head, top, std::ignore) = m::top(std::nothrow, room_id); opts.head_must_exist || opts.history
if(top < 0 && (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 throw error
{ {
fault::STATE, "Found nothing for room %s", fault::STATE, "Required head for room %s not found.",
string_view{room_id} string_view{room_id}
}; };
m::room room{room_id, head}; const m::room room
m::room::state state{room}; {
room_id, head
};
const m::room::state state
{
room
};
wopts.root_in = state.root_id; wopts.root_in = state.root_id;
dbs::write(txn, event, wopts); dbs::write(txn, event, wopts);
write_commit(eval); write_commit(eval);