Skip to content
Browse files

Cache availability_helpers, to reduce SQL overhead

  • Loading branch information...
OdyX committed Mar 24, 2019
1 parent 7acbe29 commit e3f320e16e3a9b7527cf024cfc215b4d8caef41e
Showing with 6 additions and 4 deletions.
  1. +6 −4 apps/challenge/views/
@@ -29,6 +29,7 @@
from django.db.models import Case, Count, F, IntegerField, Q, When
from django.http import HttpResponseRedirect
from django.template.defaultfilters import date, time
from django.utils.functional import cached_property
from django.utils.translation import ugettext as u, ugettext_lazy as _
from django.views.generic import ListView
from django.views.generic.detail import DetailView
@@ -201,6 +202,7 @@ def current_availabilities(self):
def current_availabilities_present(self):
return self.current_availabilities().exclude(availability='n')

def available_helpers(self):
# Only take available people
# Fill in the helpers with the ones we currently have
@@ -696,28 +698,28 @@ def get_initial(self):
super(SeasonStaffChoiceUpdateView, self)

def get_form_kwargs(self):
form_kwargs = \
super(SeasonStaffChoiceUpdateView, self).get_form_kwargs()
form_kwargs['available_helpers'] = self.available_helpers()
form_kwargs['available_helpers'] = self.available_helpers
return form_kwargs

def get_context_data(self, **kwargs):
context = \
super(SeasonStaffChoiceUpdateView, self).get_context_data(**kwargs)
context['available_helpers'] = self.available_helpers()
context['available_helpers'] = self.available_helpers
return context

def form_valid(self, form):
# Update all staff choices
for session in self.object.sessions_with_qualifs:
session_helpers = {} # Those picked for the season
session_non_helpers = {} # Those not picked for the season
for helper_category, helpers in self.available_helpers():
for helper_category, helpers in self.available_helpers:
for helper in helpers:
fieldkey = STAFF_FIELDKEY.format(,

0 comments on commit e3f320e

Please sign in to comment.
You can’t perform that action at this time.