From 261151f539c2ad160a32a6bc56bbb6d1e62daf59 Mon Sep 17 00:00:00 2001 From: Jason Volk Date: Fri, 5 Jul 2019 22:01:34 -0700 Subject: [PATCH] ircd::m::fetch: Remove ambiguating event_id() util. --- include/ircd/m/event/fetch.h | 3 --- ircd/m_event.cc | 19 ----------------- ircd/m_room.cc | 31 ++++++++++++++-------------- modules/client/rooms/send.cc | 2 +- modules/console.cc | 6 +++--- modules/federation/sender.int.h | 2 +- modules/m_fetch.cc | 16 +++++++------- modules/m_receipt.cc | 6 +++--- modules/m_room_aliases.cc | 4 ++-- modules/m_room_canonical_alias.cc | 2 +- modules/m_room_history_visibility.cc | 4 ++-- modules/m_room_join_rules.cc | 2 +- modules/m_room_message.cc | 2 +- modules/m_room_power_levels.cc | 4 ++-- modules/m_room_server_acl.cc | 2 +- 15 files changed, 42 insertions(+), 63 deletions(-) diff --git a/include/ircd/m/event/fetch.h b/include/ircd/m/event/fetch.h index 2c8c311d0..20f24b3ad 100644 --- a/include/ircd/m/event/fetch.h +++ b/include/ircd/m/event/fetch.h @@ -57,9 +57,6 @@ struct ircd::m::event::fetch fetch(const id &, const opts & = default_opts); fetch(const idx &, const opts & = default_opts); fetch(const opts & = default_opts); - - static bool event_id(const idx &, std::nothrow_t, const id::closure &); - static void event_id(const idx &, const id::closure &); }; namespace ircd::m diff --git a/ircd/m_event.cc b/ircd/m_event.cc index f57a26e1e..4b1b65a09 100644 --- a/ircd/m_event.cc +++ b/ircd/m_event.cc @@ -1382,25 +1382,6 @@ decltype(ircd::m::event::fetch::default_opts) ircd::m::event::fetch::default_opts {}; -void -ircd::m::event::fetch::event_id(const idx &idx, - const id::closure &closure) -{ - if(!get(std::nothrow, idx, "event_id", closure)) - throw m::NOT_FOUND - { - "%lu not found in database", idx - }; -} - -bool -ircd::m::event::fetch::event_id(const idx &idx, - std::nothrow_t, - const id::closure &closure) -{ - return get(std::nothrow, idx, "event_id", closure); -} - // // event::fetch::fetch // diff --git a/ircd/m_room.cc b/ircd/m_room.cc index fdb83264c..b87afea07 100644 --- a/ircd/m_room.cc +++ b/ircd/m_room.cc @@ -970,7 +970,7 @@ ircd::m::top(std::nothrow_t, event::id::buf{}, depth, event_idx }; - event::fetch::event_id(event_idx, std::nothrow, [&ret] + m::event_id(event_idx, std::nothrow, [&ret] (const event::id &event_id) { std::get(ret) = event_id; @@ -1505,7 +1505,7 @@ const (const event::idx &idx) { bool ret{true}; - event::fetch::event_id(idx, std::nothrow, [&ret, &closure] + m::event_id(idx, std::nothrow, [&ret, &closure] (const event::id &event_id) { ret = closure(event_id); @@ -1820,14 +1820,7 @@ ircd::m::event::id::buf ircd::m::room::messages::event_id() const { - event::id::buf ret; - event::fetch::event_id(this->event_idx(), [&ret] - (const event::id &event_id) - { - ret = event_id; - }); - - return ret; + return m::event_id(this->event_idx(), std::nothrow); } uint64_t @@ -1985,10 +1978,18 @@ ircd::m::room::state::get(const string_view &type, const event::id::closure &closure) const { - get(type, state_key, event::closure_idx{[&closure] + get(type, state_key, event::closure_idx{[&] (const event::idx &idx) { - event::fetch::event_id(idx, closure); + if(!m::event_id(idx, std::nothrow, closure)) + throw m::NOT_FOUND + { + "(%s,%s) in %s idx:%lu event_id :not found", + type, + state_key, + string_view{room_id}, + idx, + }; }}); } @@ -2058,7 +2059,7 @@ const return get(std::nothrow, type, state_key, event::closure_idx{[&closure] (const event::idx &idx) { - event::fetch::event_id(idx, std::nothrow, closure); + m::event_id(idx, std::nothrow, closure); }}); } @@ -2223,7 +2224,7 @@ const (const event::idx &idx) { bool ret{true}; - event::fetch::event_id(idx, std::nothrow, [&ret, &closure] + m::event_id(idx, std::nothrow, [&ret, &closure] (const event::id &id) { ret = closure(id); @@ -2405,7 +2406,7 @@ const (const event::idx &idx) { bool ret{true}; - event::fetch::event_id(idx, std::nothrow, [&ret, &closure] + m::event_id(idx, std::nothrow, [&ret, &closure] (const event::id &id) { ret = closure(id); diff --git a/modules/client/rooms/send.cc b/modules/client/rooms/send.cc index 097c79387..88df7e1da 100644 --- a/modules/client/rooms/send.cc +++ b/modules/client/rooms/send.cc @@ -154,7 +154,7 @@ save_transaction_id(const m::event &event, if(!eval.copts->client_txnid) return; - if(!json::get<"event_id"_>(event)) + if(!event.event_id) return; assert(my_host(at<"origin"_>(event))); diff --git a/modules/console.cc b/modules/console.cc index f57e022fc..a26f9457d 100644 --- a/modules/console.cc +++ b/modules/console.cc @@ -7421,7 +7421,7 @@ console_cmd__eval__file(opt &out, const string_view &line) if(room_id && json::get<"room_id"_>(event) != room_id) continue; - if(event_id && json::get<"event_id"_>(event) != event_id) + if(event_id && event.event_id != event_id) continue; if(sender && json::get<"sender"_>(event) != sender) @@ -8569,7 +8569,7 @@ console_cmd__room__state(opt &out, const string_view &line) << std::left << " ] [ " << std::setw(50) << state_key << std::left << " ] " - << std::setw(72) << json::get<"event_id"_>(event) + << std::setw(72) << string_view{event.event_id} << std::left << " " ; @@ -10475,7 +10475,7 @@ console_cmd__user__tokens(opt &out, const string_view &line) << " " << pretty(now - ost) << " ago" << " " - << json::get<"event_id"_>(event); + << string_view{event.event_id}; if(clear) diff --git a/modules/federation/sender.int.h b/modules/federation/sender.int.h index 21c371bd0..21f818fad 100644 --- a/modules/federation/sender.int.h +++ b/modules/federation/sender.int.h @@ -37,7 +37,7 @@ unit::unit(std::string s, const enum type &type) } unit::unit(const m::event &event) -:type{json::get<"event_id"_>(event)? PDU : EDU} +:type{event.event_id? PDU : EDU} ,s{[this, &event]() -> std::string { switch(this->type) diff --git a/modules/m_fetch.cc b/modules/m_fetch.cc index de670e9d3..16f3dd9c7 100644 --- a/modules/m_fetch.cc +++ b/modules/m_fetch.cc @@ -123,7 +123,7 @@ try const m::event::id &event_id { - at<"event_id"_>(event) + event.event_id }; const m::room::id &room_id @@ -148,7 +148,7 @@ try { log, "%s %s %s ac:%zu ae:%zu pc:%zu pe:%zu pf:%zu", loghead(eval), - json::get<"event_id"_>(event), + string_view{event.event_id}, json::get<"room_id"_>(event), tab.auth_count, tab.auth_exists, @@ -163,7 +163,7 @@ catch(const std::exception &e) { log, "%s %s :%s", loghead(eval), - json::get<"event_id"_>(event), + string_view{event.event_id}, e.what(), }; @@ -202,7 +202,7 @@ ircd::m::fetch::hook_handle_auth(const event &event, { log, "%s %s auth_events:%zu hit:%zu miss:%zu", loghead(eval), - at<"event_id"_>(event), + string_view{event.event_id}, tab.auth_count, tab.auth_exists, tab.auth_count - tab.auth_exists, @@ -227,7 +227,7 @@ ircd::m::fetch::hook_handle_auth(const event &event, throw vm::error { vm::fault::EVENT, "Failed to fetch auth_events for %s in %s", - json::get<"event_id"_>(event), + string_view{event.event_id}, json::get<"room_id"_>(event) }; @@ -284,7 +284,7 @@ ircd::m::fetch::hook_handle_prev(const event &event, { log, "%s %s prev_events:%zu hit:%zu miss:%zu fetching:%zu", loghead(eval), - at<"event_id"_>(event), + string_view{event.event_id}, tab.prev_count, tab.prev_exists, tab.prev_count - tab.prev_exists, @@ -317,7 +317,7 @@ ircd::m::fetch::hook_handle_prev(const event &event, throw vm::error { vm::fault::EVENT, "Failed to fetch any prev_events for %s in %s", - json::get<"event_id"_>(event), + string_view{event.event_id}, json::get<"room_id"_>(event) }; @@ -329,7 +329,7 @@ ircd::m::fetch::hook_handle_prev(const event &event, { vm::fault::EVENT, "Failed to fetch all %zu required prev_events for %s in %s", tab.prev_count, - json::get<"event_id"_>(event), + string_view{event.event_id}, json::get<"room_id"_>(event) }; } diff --git a/modules/m_receipt.cc b/modules/m_receipt.cc index 4b3dd943d..5a95a39cf 100644 --- a/modules/m_receipt.cc +++ b/modules/m_receipt.cc @@ -418,7 +418,7 @@ handle_implicit_receipt(const m::event &event, m::vm::eval &eval) try { - if(!json::get<"event_id"_>(event)) + if(!event.event_id) return; const m::user::id &user_id @@ -455,7 +455,7 @@ catch(const std::exception &e) log::error { receipt_log, "Implicit receipt hook for %s :%s", - json::get<"event_id"_>(event), + string_view{event.event_id}, e.what(), }; } @@ -576,7 +576,7 @@ catch(const std::exception &e) log::error { receipt_log, "ircd.read hook on %s for federation broadcast :%s", - json::get<"event_id"_>(event), + string_view{event.event_id}, e.what(), }; } diff --git a/modules/m_room_aliases.cc b/modules/m_room_aliases.cc index 79747c425..3921d56ce 100644 --- a/modules/m_room_aliases.cc +++ b/modules/m_room_aliases.cc @@ -154,7 +154,7 @@ _changed_aliases(const m::event &event, m::log, "Updated aliases of %s by %s in %s with %s", string_view{room_id}, json::get<"sender"_>(event), - json::get<"event_id"_>(event), + string_view{event.event_id}, string_view{alias}, }; } @@ -165,7 +165,7 @@ _changed_aliases(const m::event &event, m::log, "Updating aliases of %s by %s in %s with %s :%s", string_view{room_id}, json::get<"sender"_>(event), - json::get<"event_id"_>(event), + string_view{event.event_id}, string_view{alias}, e.what(), }; diff --git a/modules/m_room_canonical_alias.cc b/modules/m_room_canonical_alias.cc index a08d14c2a..ce4c0d4b8 100644 --- a/modules/m_room_canonical_alias.cc +++ b/modules/m_room_canonical_alias.cc @@ -53,7 +53,7 @@ _changed_canonical_alias(const m::event &event, string_view{room_id}, string_view{alias}, json::get<"sender"_>(event), - json::get<"event_id"_>(event), + string_view{event.event_id}, string_view{event_id} }; } diff --git a/modules/m_room_history_visibility.cc b/modules/m_room_history_visibility.cc index 92eb10da7..4657c8e03 100644 --- a/modules/m_room_history_visibility.cc +++ b/modules/m_room_history_visibility.cc @@ -112,7 +112,7 @@ ircd::m::visible(const m::event &event, { const m::room room { - at<"room_id"_>(event), json::get<"event_id"_>(event) + at<"room_id"_>(event), event.event_id }; static const m::event::fetch::opts fopts @@ -160,7 +160,7 @@ _changed_visibility(const m::event &event, json::get<"room_id"_>(event), json::get<"content"_>(event).get("history_visibility"), json::get<"sender"_>(event), - json::get<"event_id"_>(event) + string_view{event.event_id} }; } diff --git a/modules/m_room_join_rules.cc b/modules/m_room_join_rules.cc index c51c42119..1da4e1363 100644 --- a/modules/m_room_join_rules.cc +++ b/modules/m_room_join_rules.cc @@ -64,7 +64,7 @@ _changed_rules_notify(const m::event &event, m::log, "%s changed join_rules in %s [%s] to %s", json::get<"sender"_>(event), json::get<"room_id"_>(event), - json::get<"event_id"_>(event), + string_view{event.event_id}, json::get<"content"_>(event).get("join_rule"), }; } diff --git a/modules/m_room_message.cc b/modules/m_room_message.cc index dbc345073..64abe213e 100644 --- a/modules/m_room_message.cc +++ b/modules/m_room_message.cc @@ -29,7 +29,7 @@ _message_notify(const m::event &event, { m::log, "%s said %s in %s %s :%s%s", json::get<"sender"_>(event), - json::get<"event_id"_>(event), + string_view{event.event_id}, json::get<"room_id"_>(event), json::get<"content"_>(event).get("msgtype"), trunc(body, 128), diff --git a/modules/m_room_power_levels.cc b/modules/m_room_power_levels.cc index 42d97c651..d3b14e0b8 100644 --- a/modules/m_room_power_levels.cc +++ b/modules/m_room_power_levels.cc @@ -27,7 +27,7 @@ _has_power(const m::event &event, const auto &event_id { - json::get<"event_id"_>(event) + event.event_id }; if(!room_id || !event_id) // Not evaluated here @@ -113,7 +113,7 @@ _changed_levels(const m::event &event, m::log, "%s changed power_levels in %s [%s]", json::get<"sender"_>(event), json::get<"room_id"_>(event), - json::get<"event_id"_>(event) + string_view{event.event_id} }; } diff --git a/modules/m_room_server_acl.cc b/modules/m_room_server_acl.cc index 087b7dd02..0256d1380 100644 --- a/modules/m_room_server_acl.cc +++ b/modules/m_room_server_acl.cc @@ -71,7 +71,7 @@ ircd::m::on_changed_room_server_acl(const event &event, m::log, "%s changed server access control list in %s [%s]", json::get<"sender"_>(event), json::get<"room_id"_>(event), - json::get<"event_id"_>(event) + string_view{event.event_id}, }; }