-
Notifications
You must be signed in to change notification settings - Fork 20
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
[#2540] Allow listing more projects in the directory #2541
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.
Looks good. A pair of optional small fixes!
akvo/rsr/models/project.py
Outdated
return True | ||
else: | ||
return False | ||
budget_items = self.budget_items.all() |
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.
I think you can do something like this:
other_currencies = self.budget_items.values_list('currency', flat=True).distinct()
to get a list of extra currencies. Might be a little quicker, letting the DB do the filtering...
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.
It's a trade off between making an extra query vs. using the budget_items
which were already pre-fetched. We probably need to measure which one is better for the average case. I'll play around a little, with this code, and get back.
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.
Looks like the Python iteration is about a hundred times faster, when the budget_items
have been pre-fetched and there are only a couple of them.
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.
Right and we're getting them anyway. Interesting!
from django.test import TestCase | ||
|
||
|
||
@skip('Needs Django >= 1.8') |
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.
Cool! We need to upgrade!
akvo/rsr/views/project.py
Outdated
@@ -96,7 +96,8 @@ def directory(request): | |||
|
|||
# Build page | |||
page = request.GET.get('page') | |||
page, paginator, page_range = pagination(page, sorted_projects, 10) | |||
limit = request.GET.get('limit', 10) |
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.
Maybe have the default value come from settings? Gives us another way of controlling this.
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.
👍
The query for `partnership_more_link` is very slow, and adding a `select_related` makes it quite a lot faster. This looks like the only query that is slow on the project listing page. We add a `limit` parameter to specify the number of projects to be listed in the directory, with the default value being 10. Closes #2540
e91a495
to
67c133c
Compare
And optimize check for multiple currencies in a project
And refactor codelist_name function to use this. These functions are called in so many places, that caching them should bring significant benefits all over the site. RSR seems to already have memcached configured and it's a shame that we don't use it anywhere except for thumbnails. A lot of things can benefit from caching!
Added a simple performance test example for the project directory listing, but the test cannot be run with the current version of Django. It can be un-skipped when Django is updated!
67c133c
to
a034dcf
Compare
The query for
partnership_more_link
is very slow, and adding aselect_related
makes it quite a lot faster. This looks like the only querythat is slow on the project listing page.
We add a
limit
parameter to specify the number of projects to be listed inthe directory, with the default value being 10.
Closes #2540