Skip to content

Commit

Permalink
Skip elements that are created then deleted
Browse files Browse the repository at this point in the history
Just like Overpass
  • Loading branch information
CloudNiner committed Oct 27, 2020
1 parent 215ad85 commit 2070563
Showing 1 changed file with 21 additions and 11 deletions.
32 changes: 21 additions & 11 deletions app/onramp/diff.py
Original file line number Diff line number Diff line change
Expand Up @@ -53,14 +53,26 @@ def augmented_diff(
for block in osc:
for e in block:
action_key = e.tag + "/" + e.get("id")
# Always ensure we're updating to the latest version of an object for the diff
if action_key in actions:
newest_version = int(actions[action_key].element.get("version"))
e_version = int(e.get("version"))
if e_version < newest_version:
old_action = actions[action_key]
old_version = int(old_action.element.get("version"))
new_version = int(e.get("version"))
# Remove elements created and then deleted in the same interval
# TODO: This will not capture any element that is also modified
# between create and delete.
if old_action.type == "create" and block.tag == "delete":
logger.warning(
"Element {}, version {} is less than version {}".format(
action_key, e_version, newest_version
"Skipping element {} which was created and deleted within the interval".format(
action_key
)
)
del actions[action_key]
continue
# Always ensure we're updating to the latest version of an object for the diff
elif new_version < old_version:
logger.warning(
"Skipping element {}, new version {} is older than version {}".format(
action_key, new_version, old_version
)
)
continue
Expand Down Expand Up @@ -102,11 +114,9 @@ def rebuild_old_element(elem):
ll = get_lat_lon(elem_id, False)
elem.set("lon", ll[0])
elem.set("lat", ll[1])
# If we fail to retrieve a location, it typically means:
# 1. A node was created and then deleted within the diff interval. In
# the future we should remove these operations from the diff entirely.
# 2. OSMX db only contains locations for a bounding box and we've requested
# a location that was trimmed during import.
# If we fail to retrieve a location, it typically means that the OSMX db only
# contains locations for a bounding box and we've requested a location that
# was trimmed during import.
# If you see this error, verify that you're seeing one of the cases above.
# If not open an issue!
except TypeError:
Expand Down

0 comments on commit 2070563

Please sign in to comment.