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

Geocoder: Pelias: remove exact duplicates #807

Open
wants to merge 3 commits into
base: master
Choose a base branch
from

Conversation

miles-grant-ibigroup
Copy link
Collaborator

It seems like we've been seeing some exact duplicates coming back from Pelias in some cases. This PR removes them.

This will slow things down, but hopefully not too much.

Copy link
Contributor

@daniel-heppner-ibigroup daniel-heppner-ibigroup left a comment

Choose a reason for hiding this comment

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

Going to approve it since I'm first reviewer, but I'll leave my comments to the second reviewer to decide whether they should be fixed (if they're not already fixed)

packages/geocoder/src/geocoders/pelias.ts Outdated Show resolved Hide resolved
rewriteAutocompleteResponse(response: unknown): MultiGeocoderResponse {
const features = (response as FeatureCollection)?.features;

const filtered = features?.filter(
Copy link
Contributor

Choose a reason for hiding this comment

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

is there some fun CSy way of sorting this first to make it more efficient?

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

If we were writing in a language with actual arrays yes you could sort by name keep a fixed array iterate by index and then stop the check once you got past the first letter you're checking against. But given that we will never be sorting more than ~50 items I think we're ok to prioritize code cleanliness. Also I don't think JS supports native pointers so how would you maintain a real array of sorted strings? Maybe a second array where you store string lengths but then you'd have to allocate a large enough string array and you'd somehow have to sync up a separate array of coordinates... yikes

f =>
f?.properties?.name === feature?.properties?.name &&
// This is unclean, but we know geometry will never contain objects
JSON.stringify((feature?.geometry as Point)?.coordinates) ===
Copy link
Contributor

Choose a reason for hiding this comment

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

would it not be faster to compare the individual lat lon numbers rather than stringifying the coordinates object?

Copy link
Contributor

Choose a reason for hiding this comment

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

if you put them together in an AND then 99% of the time it won't even evaluate the second half of the AND because the first half of the coordinate won't match

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

You are right but again I prioritized cleanliness. If we compare coordinates we'd have to cast 4 times and we'd probably have to break into a function block

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants