From 14f8ef4f4458861418c129b9751286fca0b2210c Mon Sep 17 00:00:00 2001 From: Ryan Petrello Date: Tue, 10 Sep 2019 08:14:20 -0400 Subject: [PATCH] move the oauth2 last_used update to the bottom of the request this avoids acquiring a row lock (and holding it for the duration of transactions which include a very slow query) --- awx/main/models/oauth.py | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/awx/main/models/oauth.py b/awx/main/models/oauth.py index 7c778e7b7d..3a89790e80 100644 --- a/awx/main/models/oauth.py +++ b/awx/main/models/oauth.py @@ -3,7 +3,7 @@ import re # Django from django.core.validators import RegexValidator -from django.db import models +from django.db import models, connection from django.utils.timezone import now from django.utils.translation import ugettext_lazy as _ from django.conf import settings @@ -121,7 +121,7 @@ class OAuth2AccessToken(AbstractAccessToken): valid = super(OAuth2AccessToken, self).is_valid(scopes) if valid: self.last_used = now() - self.save(update_fields=['last_used']) + connection.on_commit(lambda: self.save(update_fields=['last_used'])) return valid def save(self, *args, **kwargs):