From d0ed0cea23e00630c4327ae246de0dff952a5838 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Norman=20J=C3=A4ckel?= Date: Fri, 2 Dec 2016 15:47:57 +0100 Subject: [PATCH] Improved speed of motion numbering. --- openslides/agenda/signals.py | 8 ++++++-- openslides/motions/views.py | 9 +++++++-- 2 files changed, 13 insertions(+), 4 deletions(-) diff --git a/openslides/agenda/signals.py b/openslides/agenda/signals.py index 35e2fa90d..83679a5d0 100644 --- a/openslides/agenda/signals.py +++ b/openslides/agenda/signals.py @@ -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) diff --git a/openslides/motions/views.py b/openslides/motions/views.py index 1e486953b..d6a072481 100644 --- a/openslides/motions/views.py +++ b/openslides/motions/views.py @@ -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})