From 321de47ec521ba0e004bfa19f7320c1a70449156 Mon Sep 17 00:00:00 2001 From: Claude Date: Sat, 21 Nov 2026 19:44:16 +0000 Subject: [PATCH] Collect relation node members and way nodes in one pass at past dates Down recursion (>) over relations collected the relations' node members and the ways' nodes in two separate passes over the node blocks, then took the union. The current-data case already does it in one pass. At a past date ([date:], or the old side of [diff:]), it still read every node block twice, current and attic files, and both passes also read the node metadata that attic queries use to check versions. add_nw_member_objects now uses relation_and_way_node_members, which handles attic relations and ways, for dates too, unless a range restriction is given (local). It merges the two id lists and the two range sets, then reads the node blocks once. The final keep_matching_skeletons step picks the version valid at the date, as before. On the Nova Scotia history database: [date:"2018-01-01T00:00:00Z"][out:csv(::count)]; rel[route=hiking]; (._;>;); out count; drops from 1.78 s to 1.13 s, with identical output. Co-Authored-By: Claude Opus 5.5 Claude-Session: https://claude.ai/code/session_01736kJUqyDw9zM3Bkh2W2QT --- src/overpass_api/data/collect_members.cc | 15 +++++++++++---- 1 file changed, 11 insertions(+), 4 deletions(-) diff --git a/src/overpass_api/data/collect_members.cc b/src/overpass_api/data/collect_members.cc index 8e02c33ce..52404cb2e 100644 --- a/src/overpass_api/data/collect_members.cc +++ b/src/overpass_api/data/collect_members.cc @@ -1102,8 +1102,13 @@ void add_nw_member_objects(Request_Context& context, const Set& input_set, Set& return; } - Timeless< Uint32_Index, Node_Skeleton > rel_nodes - = relation_node_members(context, input_set.relations, input_set.attic_relations, ranges_32, {}, true); + // For a date without a range restriction, the relations' node members are collected below, + // in the same pass over the node blocks as the ways' nodes. + bool one_pass = !ranges_32_; + Timeless< Uint32_Index, Node_Skeleton > rel_nodes; + if (!one_pass) + rel_nodes = relation_node_members( + context, input_set.relations, input_set.attic_relations, ranges_32, {}, true); if (context.get_desired_timestamp() == NOW) { @@ -1136,8 +1141,10 @@ void add_nw_member_objects(Request_Context& context, const Set& input_set, Set& indexed_set_union(all_ways.current, source_ways); indexed_set_union(all_ways.attic, source_attic_ways); - Timeless< Uint32_Index, Node_Skeleton > more_nodes - = way_members(context, all_ways.current, all_ways.attic, 0, Ranges< Uint32_Index >::global(), {}, true); + Timeless< Uint32_Index, Node_Skeleton > more_nodes = one_pass + ? relation_and_way_node_members( + context, input_set.relations, input_set.attic_relations, all_ways.current, all_ways.attic) + : way_members(context, all_ways.current, all_ways.attic, 0, Ranges< Uint32_Index >::global(), {}, true); more_nodes.sort(); sort_second(into.nodes); sort_second(into.attic_nodes);