-
Notifications
You must be signed in to change notification settings - Fork 35
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
base: master
Are you sure you want to change the base?
Geocoder: Pelias: remove exact duplicates #807
Conversation
There was a problem hiding this 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)
rewriteAutocompleteResponse(response: unknown): MultiGeocoderResponse { | ||
const features = (response as FeatureCollection)?.features; | ||
|
||
const filtered = features?.filter( |
There was a problem hiding this comment.
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?
There was a problem hiding this comment.
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) === |
There was a problem hiding this comment.
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?
There was a problem hiding this comment.
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
There was a problem hiding this comment.
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
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.