From 12420dc644d57f2059bbf7cd7c3536eb02f0ac7d Mon Sep 17 00:00:00 2001 From: Pavel Emelyanov Date: Mon, 2 Jun 2025 18:43:17 +0300 Subject: [PATCH] api: Shorten get_host_to_id_map() handler The handler does - gets host IDs from local token metadata - for each ID gets the host IP and generates IP:ID std::pair - converts the sequence of generated pairs into std::unordered_map - converts the unordered map into vector of jsonable key:value objects This patch removes the 3rd step and makes the needed jsonable object in step 2 directly, thus eliminating the interposing unordered_map creation. Signed-off-by: Pavel Emelyanov Closes scylladb/scylladb#24354 --- api/token_metadata.cc | 13 ++++++++----- 1 file changed, 8 insertions(+), 5 deletions(-) diff --git a/api/token_metadata.cc b/api/token_metadata.cc index 081388d329..fde9e04027 100644 --- a/api/token_metadata.cc +++ b/api/token_metadata.cc @@ -74,11 +74,14 @@ void set_token_metadata(http_context& ctx, routes& r, sharded res; - auto map = tm.local().get()->get_host_ids() | - std::views::transform([&g] (locator::host_id id) { return std::make_pair(g.local().get_address_map().get(id), id); }) | - std::ranges::to(); - return map_to_key_value(std::move(map), res); + return tm.local().get()->get_host_ids() + | std::views::transform([&g] (locator::host_id id) { + ss::mapper m; + m.key = fmt::to_string(g.local().get_address_map().get(id)); + m.value = fmt::to_string(id); + return m; + }) + | std::ranges::to>(); }); static auto host_or_broadcast = [&tm](const_req req) {