Skip to content
This repository has been archived by the owner on Sep 19, 2018. It is now read-only.

Commit

Permalink
Show only countries from the current year by default
Browse files Browse the repository at this point in the history
We were fetching all events from the DB before, to show a list of
countries. That's pretty slow. We now do this only if the "Show past
events" option is selected by the user.

The method still needs to be optimized a lot, since it loads all events,
then traverses them in the code just to fetch their countries.
  • Loading branch information
mitio committed Oct 12, 2016
1 parent d72f604 commit 9f7f96c
Show file tree
Hide file tree
Showing 2 changed files with 4 additions and 3 deletions.
5 changes: 3 additions & 2 deletions web/processors/event.py
Original file line number Diff line number Diff line change
Expand Up @@ -45,10 +45,11 @@ def list_countries():
return all_countries


def list_active_countries():
def list_active_countries(with_past_events=False):
""" List countries with at least an Event associated """
start_year = 2014 if with_past_events else datetime.datetime.now().year
events_countries = Event.objects.filter(
start_date__gte=datetime.date(2014, 1, 1),
start_date__gte=datetime.date(start_year, 1, 1),
status='APPROVED'
).only('country').distinct()

Expand Down
2 changes: 1 addition & 1 deletion web/views/events.py
Original file line number Diff line number Diff line change
Expand Up @@ -71,7 +71,7 @@ def index(request):
lan_lon = (58.08695, 5.58121)

ambassadors = get_ambassadors(country['country_code'])
all_countries = list_active_countries()
all_countries = list_active_countries(with_past_events=(past == 'yes'))

return render_to_response(
template, {
Expand Down

0 comments on commit 9f7f96c

Please sign in to comment.