From 5856c2fd0e976ca864a14c90feab92f133832bbe Mon Sep 17 00:00:00 2001 From: Jason Volk Date: Tue, 21 Feb 2023 20:10:16 -0800 Subject: [PATCH] ircd::m::room::stats: Optimize byte counter with pipelined iteration. --- matrix/room_stats.cc | 25 ++++++++----------------- 1 file changed, 8 insertions(+), 17 deletions(-) diff --git a/matrix/room_stats.cc b/matrix/room_stats.cc index 65e1382f7..fbc764c68 100644 --- a/matrix/room_stats.cc +++ b/matrix/room_stats.cc @@ -32,25 +32,16 @@ size_t ircd::m::room::stats::bytes_json(const m::room &room) { size_t ret(0); - for(m::room::events it(room); it; --it) + const room::iterate iterate { - const m::event::idx &event_idx - { - it.event_idx() - }; + room + }; - const byte_view key - { - event_idx - }; - - static const db::gopts gopts - { - .cache = false, - }; - - ret += db::bytes_value(m::dbs::event_json, key, gopts); - } + iterate.for_each([&ret] + (const string_view &event, const auto &depth, const auto &event_idx) + { + ret += size(event); + }); return ret; }