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

Add support for a 'country' filter in query parameters #302

Merged
merged 4 commits into from
Nov 22, 2017

Conversation

mhl
Copy link
Contributor

@mhl mhl commented Oct 3, 2017

This change means that you can add ?country=E (say) to queries for
multiple areas to restrict the results to those areas that have a
Country with code E.

This should be particularly helpful for global.mapit.mysociety.org
if we set an appropriate Country for each Area, since one is almost
always interested in results from a particular country.

Fixes #55

@mhl
Copy link
Contributor Author

mhl commented Oct 6, 2017

n.b. The test failures here are due to changes in the Travis build environment - I've made a pull request with fixes for those errors here so once that's merge, this should be rebased over that.

args['polygons__in'] = geoms
areas = Area.objects.filter(**args)
geoms = list(Geometry.objects.filter(polygon__contains=location).defer('polygon'))
args['polygons__in'] = geoms
Copy link
Member

Choose a reason for hiding this comment

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

To continue this, these two lines could now be args['polygons__polygon__contains'] = location I assume?

This change means that you can add '?country=E' (say) to queries for
multiple areas to restrict the results to those areas that have a
Country with code 'E'.

This should be particularly helpful for global.mapit.mysociety.org
if we set an appropriate Country for each Area, since one is almost
always interested in results from a particular country.

Fixes #55
Presumably the same fix for odd PostGIS query planning needs to be done
for the new 'country' filter as for 'type', since these GET query
parameters modify the shape of the query in the same way.
We have migrated MapIt to use Postgres 9.6 and PostGIS 2.3 now; Matthew
Somerville investigated whether this sub-optimal query planning still
happens with those versions, but it doesn't seem to. The query time is
considerably faster as well. So, we believe that this workaround should
no longer be necessary, but this commit should revert cleanly if in
practice we discover the problem is still present with some other
variant of these queries or data.
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