close
Skip to content

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

Merged
dracos merged 4 commits into
masterfrom
add-country-filter
Nov 22, 2017
Merged

Add support for a 'country' filter in query parameters#302
dracos merged 4 commits into
masterfrom
add-country-filter

Conversation

@mhl
Copy link
Copy Markdown
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 mhl force-pushed the add-country-filter branch from 28682e2 to 8150dd8 Compare October 3, 2017 08:19
@mhl
Copy link
Copy Markdown
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.

Comment thread mapit/views/areas.py Outdated
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
Copy Markdown
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?

@mhl mhl force-pushed the add-country-filter branch from 887491d to 50adce0 Compare October 26, 2017 10:21
mhl added 4 commits October 26, 2017 15:41
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