From 46bcf5ba8da9bf1b0d49d4da145bdf655f26e90d 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 | 13 +++++-------- 1 file changed, 5 insertions(+), 8 deletions(-) diff --git a/arches/app/models/tile.py b/arches/app/models/tile.py index 4b5af19946e..8c61bd8e74f 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" - - if creating_new_tile is False: - existing_model = models.TileModel.objects.get(pk=self.tileid) - else: + existing_model = models.TileModel.objects.filter(pk=self.tileid).first() + creating_new_tile = existing_model is None + edit_type = "tile edit" + if creating_new_tile: + edit_type = "tile create" self.populate_missing_nodes() # this section moves the data over from self.data to self.provisionaledits if certain users permissions are in force