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

First stab at fixing /nearest #305

Merged
merged 2 commits into from
Oct 24, 2017
Merged

First stab at fixing /nearest #305

merged 2 commits into from
Oct 24, 2017

Conversation

davea
Copy link
Member

@davea davea commented Oct 24, 2017

Something about the recent move to Postgres 9.6 and PostGIS 2.3 caused
the /nearest query to take much longer than 10 seconds to complete.

This commit updates the query to use the ‘<->’ centroid distance operator
instead, which makes better use of the geoindex and is much faster to
execute.

Handily the work @dracos did to introduce the TrigramDistance function
into Django 1.10 was easily adapted for this purpose, as it uses the
same operator.

This needs a bit of tidying and refactoring before merging really.

@dracos dracos force-pushed the nearest_no_longer_knackered branch from c5fcb45 to a1656db Compare October 24, 2017 16:58
The nearest postcode lookup performance reduced dramatically when tried
with Postgres 9.6 and PostGIS 2.3. This commit updates the query to use
the ‘<->’ centroid distance operator instead, which makes better use of
the geoindex and is much faster to execute.

Handily, the work @dracos did to introduce the TrigramDistance function
into Django 1.10 was easily adaptable for this purpose, as the operator
used is the same.
@dracos dracos force-pushed the nearest_no_longer_knackered branch from a1656db to 4d15041 Compare October 24, 2017 18:39
@dracos dracos merged commit 4d15041 into master Oct 24, 2017
@dracos
Copy link
Member

dracos commented Oct 24, 2017

Tweaked after merge to transform to 4326. And to fetch 100 rows and take actual closest, as we're using geometry not geography.

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.

2 participants