Skip to content

Commit

Permalink
fix(2079/deadlock): avoid deadlock by updating env individually (#3339)
Browse files Browse the repository at this point in the history
  • Loading branch information
gagantrivedi committed Jan 30, 2024
1 parent 0dcf4ac commit 85443a2
Showing 1 changed file with 10 additions and 5 deletions.
15 changes: 10 additions & 5 deletions api/audit/models.py
Original file line number Diff line number Diff line change
Expand Up @@ -116,16 +116,21 @@ def add_created_date(self) -> None:
is_now=True,
)
def process_environment_update(self):
from environments.models import Environment
from environments.tasks import process_environment_update

environments_filter = Q()
if self.environment_id:
environments_filter = Q(id=self.environment_id)

# Use a queryset to perform update to prevent signals being called at this point.
# Since we're re-saving the environment, we don't want to duplicate signals.
self.project.environments.filter(environments_filter).update(
updated_at=self.created_date
)
environment_ids = self.project.environments.filter(
environments_filter
).values_list("id", flat=True)

# Update environment individually to avoid deadlock
for environment_id in environment_ids:
Environment.objects.filter(id=environment_id).update(
updated_at=self.created_date
)

process_environment_update.delay(args=(self.id,))

0 comments on commit 85443a2

Please sign in to comment.