Improved speed of motion numbering.

This commit is contained in:
Norman Jäckel 2016-12-02 15:47:57 +01:00 committed by Norman Jäckel
parent dbfa470ee0
commit d0ed0cea23
2 changed files with 13 additions and 4 deletions

View File

@ -9,13 +9,17 @@ def listen_to_related_object_post_save(sender, instance, created, **kwargs):
"""
Receiver function to create agenda items. It is connected to the signal
django.db.models.signals.post_save during app loading.
Do not run caching and autoupdate if the instance as an attribute
skip_autoupdate (regardless of its truthy or falsy conent).
"""
if hasattr(instance, 'get_agenda_title'):
if created:
# If the object is created, the related_object has to be sent again.
Item.objects.create(content_object=instance)
inform_changed_data(instance)
else:
if not hasattr(instance, 'skip_autoupdate'):
inform_changed_data(instance)
elif not hasattr(instance, 'skip_autoupdate'):
# If the object has changed, then also the agenda item has to be sent.
inform_changed_data(instance.agenda_item)

View File

@ -420,11 +420,13 @@ class CategoryViewSet(ModelViewSet):
motion_dict[motion.pk] = motion
motions = [motion_dict[pk] for pk in motion_list]
instances = []
try:
with transaction.atomic():
for motion in motions:
motion.identifier = None
motion.save()
motion.skip_autoupdate = True # This line is to skip agenda item autoupdate. See agenda/signals.py.
motion.save(skip_autoupdate=True)
for motion in motions:
if motion.is_amendment():
@ -434,12 +436,15 @@ class CategoryViewSet(ModelViewSet):
identifier = '%s%s' % (prefix, motion.extend_identifier_number(number))
motion.identifier = identifier
motion.identifier_number = number
motion.save()
motion.save(skip_autoupdate=True)
instances.append(motion)
instances.append(motion.agenda_item)
except IntegrityError:
message = _('Error: At least one identifier of this category does '
'already exist in another category.')
response = Response({'detail': message}, status_code=400)
else:
inform_changed_data(instances)
message = _('All motions in category {category} numbered '
'successfully.').format(category=category)
response = Response({'detail': message})