More speed improvements
This commit is contained in:
parent
238b4b7f0a
commit
08bd1251a7
@ -331,7 +331,7 @@ class SpeakerManager(models.Manager):
|
||||
"""
|
||||
Manager for Speaker model. Provides a customized add method.
|
||||
"""
|
||||
def add(self, user, item):
|
||||
def add(self, user, item, skip_autoupdate=False):
|
||||
"""
|
||||
Customized manager method to prevent anonymous users to be on the
|
||||
list of speakers and that someone is twice on one list (off coming
|
||||
@ -345,7 +345,9 @@ class SpeakerManager(models.Manager):
|
||||
_('An anonymous user can not be on lists of speakers.'))
|
||||
weight = (self.filter(item=item).aggregate(
|
||||
models.Max('weight'))['weight__max'] or 0)
|
||||
return self.create(item=item, user=user, weight=weight + 1)
|
||||
speaker = self.model(item=item, user=user, weight=weight + 1)
|
||||
speaker.save(force_insert=True, skip_autoupdate=skip_autoupdate)
|
||||
return speaker
|
||||
|
||||
|
||||
class Speaker(RESTModelMixin, models.Model):
|
||||
|
@ -135,9 +135,13 @@ class ItemViewSet(ListModelMixin, RetrieveModelMixin, UpdateModelMixin, GenericV
|
||||
except (ValueError, Speaker.DoesNotExist):
|
||||
pass
|
||||
else:
|
||||
speaker.delete()
|
||||
speaker.delete(skip_autoupdate=True)
|
||||
deleted_speaker_name = speaker
|
||||
deleted_speaker_count += 1
|
||||
# send autoupdate if speakers are deleted
|
||||
if deleted_speaker_count > 0:
|
||||
inform_changed_data(item)
|
||||
|
||||
if deleted_speaker_count > 1:
|
||||
message = str(deleted_speaker_count) + ' ' + _('speakers have been removed from the list of speakers.')
|
||||
elif deleted_speaker_count == 1:
|
||||
|
@ -283,11 +283,12 @@ class Assignment(RESTModelMixin, models.Model):
|
||||
# TODO: Try to do this in a bulk create
|
||||
for candidate in self.candidates:
|
||||
try:
|
||||
Speaker.objects.add(candidate, self.agenda_item)
|
||||
Speaker.objects.add(candidate, self.agenda_item, skip_autoupdate=True)
|
||||
except OpenSlidesError:
|
||||
# The Speaker is already on the list. Do nothing.
|
||||
# TODO: Find a smart way not to catch the error concerning AnonymousUser.
|
||||
pass
|
||||
inform_changed_data(self.agenda_item)
|
||||
|
||||
return poll
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user