From b91835bc91121868a91656460be42c34a6cc41ea Mon Sep 17 00:00:00 2001 From: Jacob Walls Date: Tue, 5 Nov 2024 15:35:29 -0500 Subject: [PATCH] Avoid pessimistic exists() query --- arches/app/models/tile.py | 11 ++++------- 1 file changed, 4 insertions(+), 7 deletions(-) diff --git a/arches/app/models/tile.py b/arches/app/models/tile.py index 4b5af19946e..7b7ccc05861 100644 --- a/arches/app/models/tile.py +++ b/arches/app/models/tile.py @@ -472,14 +472,11 @@ def save(self, *args, **kwargs): self.check_for_missing_nodes() self.check_for_constraint_violation() - creating_new_tile = ( - models.TileModel.objects.filter(pk=self.tileid).exists() is False - ) - edit_type = "tile create" if (creating_new_tile is True) else "tile edit" + existing_model = models.TileModel.objects.filter(pk=self.tileid).first() + creating_new_tile = existing_model is None + edit_type = "tile create" if creating_new_tile else "tile edit" - if creating_new_tile is False: - existing_model = models.TileModel.objects.get(pk=self.tileid) - else: + if not creating_new_tile: self.populate_missing_nodes() # this section moves the data over from self.data to self.provisionaledits if certain users permissions are in force