From 7b307e61512b443dbdfe75d4729d33ccc1566714 Mon Sep 17 00:00:00 2001 From: Jason Volk Date: Wed, 31 Oct 2018 11:54:16 -0700 Subject: [PATCH] modules/vm: Simplify head fetch before write commit. --- modules/vm.cc | 31 ++++++++++++++++++++++++------- 1 file changed, 24 insertions(+), 7 deletions(-) diff --git a/modules/vm.cc b/modules/vm.cc index b13beb4ad..f38adb55a 100644 --- a/modules/vm.cc +++ b/modules/vm.cc @@ -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);