diff options
author | Étienne Loks <etienne.loks@iggdrasil.net> | 2023-08-08 12:20:07 +0200 |
---|---|---|
committer | Étienne Loks <etienne.loks@iggdrasil.net> | 2023-08-08 14:44:38 +0200 |
commit | 3f1de491d60943b8d8f82088febe2af89a8801de (patch) | |
tree | 4cf18a700614ceaad94c42175201d2683ce35dd9 /archaeological_context_records/models.py | |
parent | fbab3b61058fac36c11e17c0e502e0bf2ad57b23 (diff) | |
download | Ishtar-3f1de491d60943b8d8f82088febe2af89a8801de.tar.bz2 Ishtar-3f1de491d60943b8d8f82088febe2af89a8801de.zip |
⚡️ optimise post-treatments: prevent unnecessary cascade update (refs #5617)
Diffstat (limited to 'archaeological_context_records/models.py')
-rw-r--r-- | archaeological_context_records/models.py | 33 |
1 files changed, 17 insertions, 16 deletions
diff --git a/archaeological_context_records/models.py b/archaeological_context_records/models.py index 21640920e..f464275bf 100644 --- a/archaeological_context_records/models.py +++ b/archaeological_context_records/models.py @@ -422,12 +422,10 @@ class GeographicSubTownItem(GeoItem): has_geo_town = ( town and town.main_geodata and town.main_geodata.multi_polygon ) - if has_geo_town: - bad_towns = q_geodata_current_town - elif town: + + bad_towns = q_geodata_current_town + if town: bad_towns = q_geodata_current_town.exclude(source_id=town.id) - else: - return modified = False for bad_town in bad_towns.all(): @@ -446,15 +444,18 @@ class GeographicSubTownItem(GeoItem): if not self.main_geodata: self.main_geodata = upper.main_geodata + if modified and save: + if settings.USE_BACKGROUND_TASK and hasattr(self, "no_post_process"): + self.no_post_process() + else: + self.skip_history_when_saving = True + self._no_move = True + self._post_saved_geo = False + self._no_down_model_update = False + self.save() + if not has_geo_town: - if modified: - if save: - self.skip_history_when_saving = True - self._no_move = True - self.save() - else: - return True - return + return modified if not q_geodata_current_town.filter(source_id=town.id).count(): try: @@ -463,12 +464,12 @@ class GeographicSubTownItem(GeoItem): self.geodata.add(town.main_geodata) except (OperationalError, IntegrityError): pass + if not modified: + return False if save: post_save_geo(self.__class__, instance=self, created=False, update_fields=False, raw=False, using="default") - else: - return True - return False + return True class ContextRecord( |