Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

avoid ways/rels update for non moving node updates #1059

Closed
wants to merge 1 commit into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 5 additions & 0 deletions middle-pgsql.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -384,6 +384,11 @@ void middle_pgsql_t::nodes_set(osmium::Node const &node)
}
}

osmium::Location middle_pgsql_t::nodes_get(osmid_t osm_id)
{
return persistent_cache->get(osm_id);
}

size_t middle_query_pgsql_t::nodes_get_list(osmium::WayNodeList *nodes) const
{
return m_persistent_cache ? m_persistent_cache->get_list(nodes)
Expand Down
1 change: 1 addition & 0 deletions middle-pgsql.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -59,6 +59,7 @@ struct middle_pgsql_t : public slim_middle_t
void commit() override;

void nodes_set(osmium::Node const &node) override;
osmium::Location nodes_get(osmid_t osm_id) override;
void nodes_delete(osmid_t id) override;
void node_changed(osmid_t id) override;

Expand Down
5 changes: 5 additions & 0 deletions middle-ram.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,11 @@ void middle_ram_t::nodes_set(osmium::Node const &node)
cache->set(node.id(), node.location());
}

osmium::Location middle_ram_t::nodes_get(osmid_t osm_id)
{
return cache->get(osm_id);
}

Copy link
Contributor

@mmd-osm mmd-osm Feb 15, 2020

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

There are also other places in the code where nodes_get would have to be implemented, see compiler errors:

In file included from /home/travis/build/openstreetmap/osm2pgsql/tests/test-parse-extra-args.cpp:15:

/home/travis/build/openstreetmap/osm2pgsql/tests/mockups.hpp:7:8: note:   because the following virtual functions are pure within ‘dummy_middle_t’:

 struct dummy_middle_t : public middle_t {

        ^~~~~~~~~~~~~~

In file included from /home/travis/build/openstreetmap/osm2pgsql/tests/test-parse-extra-args.cpp:9:

/home/travis/build/openstreetmap/osm2pgsql/middle.hpp:91:30: note: 	‘virtual osmium::Location middle_t::nodes_get(osmid_t)’

     virtual osmium::Location nodes_get(osmid_t osm_id) = 0;

void middle_ram_t::ways_set(osmium::Way const &way)
{
ways.set(way.id(), new ramWay(way, extra_attributes));
Expand Down
1 change: 1 addition & 0 deletions middle-ram.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -91,6 +91,7 @@ struct middle_ram_t : public middle_t, public middle_query_t
void commit(void) override;

void nodes_set(osmium::Node const &node) override;
osmium::Location nodes_get(osmid_t osm_id) override;
size_t nodes_get_list(osmium::WayNodeList *nodes) const override;
int nodes_delete(osmid_t id);
int node_changed(osmid_t id);
Expand Down
2 changes: 2 additions & 0 deletions middle.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -88,6 +88,8 @@ struct middle_t
virtual void commit(void) = 0;

virtual void nodes_set(osmium::Node const &node) = 0;
virtual osmium::Location nodes_get(osmid_t osm_id) = 0;

virtual void ways_set(osmium::Way const &way) = 0;
virtual void relations_set(osmium::Relation const &rel) = 0;

Expand Down
15 changes: 12 additions & 3 deletions osmdata.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,8 @@
#include "osmdata.hpp"
#include "output.hpp"

int nodes_moved = 0;

osmdata_t::osmdata_t(std::shared_ptr<middle_t> mid_,
std::shared_ptr<output_t> const &out_)
: mid(mid_)
Expand Down Expand Up @@ -82,15 +84,21 @@ int osmdata_t::node_modify(osmium::Node const &node)
{
slim_middle_t *slim = dynamic_cast<slim_middle_t *>(mid.get());

slim->nodes_delete(node.id());
slim->nodes_set(node);
osmium::Location oldnode = slim->nodes_get(node.id());
if ( node.location().x() != oldnode.x() || node.location().y() != oldnode.y() ) {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

osmium::Location has both == and != operators, so node.location() != oldnode should do here.

https://github.com/osmcode/libosmium/blob/master/include/osmium/osm/location.hpp#L489

slim->nodes_delete(node.id());
slim->nodes_set(node);
nodes_moved++;
}

int status = 0;
for (auto& out: outs) {
status |= out->node_modify(node);
}

slim->node_changed(node.id());
if ( node.location().x() != oldnode.x() || node.location().y() != oldnode.y() ) {
slim->node_changed(node.id());
}

return status;
}
Expand Down Expand Up @@ -275,6 +283,7 @@ struct pending_threaded_processor : public middle_t::pending_processor {
//reset the number we've done
ids_done = 0;

fprintf(stderr, "\n%i nodes moved\n", nodes_moved);
fprintf(stderr, "\nGoing over pending ways...\n");
fprintf(stderr, "\t%zu ways are pending\n", ids_queued);
fprintf(stderr, "\nUsing %zu helper-processes\n", clones.size());
Expand Down