Skip to content

Commit

Permalink
Merge pull request #2303 from joto/fix-get-node2
Browse files Browse the repository at this point in the history
Fix two-stage processing when flat node file is used
  • Loading branch information
lonvia authored Feb 16, 2025
2 parents f872d39 + 45d16e0 commit f533ab8
Show file tree
Hide file tree
Showing 2 changed files with 47 additions and 7 deletions.
28 changes: 22 additions & 6 deletions src/middle-pgsql.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -762,17 +762,33 @@ bool middle_query_pgsql_t::node_get(osmid_t id,
{
assert(buffer);

auto const res = m_db_connection.exec_prepared("get_node", id);
if (m_store_options.nodes) {
auto const res = m_db_connection.exec_prepared("get_node", id);

if (res.num_tuples() != 1) {
return false;
if (res.num_tuples() == 1) {
build_node(id, res, 0, 0, buffer, m_store_options.with_attributes);
buffer->commit();
return true;
}
}

build_node(id, res, 0, 0, buffer, m_store_options.with_attributes);
if (m_store_options.use_flat_node_file) {
auto const location = get_node_location_flatnodes(id);
if (!location.valid()) {
return false;
}

buffer->commit();
{
osmium::builder::NodeBuilder builder{*buffer};
builder.set_id(id);
builder.set_location(location);
}

return true;
buffer->commit();
return true;
}

return false;
}

bool middle_query_pgsql_t::way_get(osmid_t id,
Expand Down
26 changes: 25 additions & 1 deletion src/middle-ram.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -283,8 +283,32 @@ bool middle_ram_t::node_get(osmid_t id, osmium::memory::Buffer *buffer) const
assert(buffer);

if (m_store_options.nodes) {
return get_object(osmium::item_type::node, id, buffer);
auto const got_it = get_object(osmium::item_type::node, id, buffer);
if (got_it) {
return true;
}
}

if (m_store_options.locations) {
osmium::Location location{};
if (m_persistent_cache) {
location = m_persistent_cache->get(id);
}
if (!location.valid()) {
location = m_node_locations.get(id);
}
if (location.valid()) {
{
osmium::builder::NodeBuilder builder{*buffer};
builder.set_id(id);
builder.set_location(location);
}

buffer->commit();
return true;
}
}

return false;
}

Expand Down

0 comments on commit f533ab8

Please sign in to comment.