fix: retry transactions who fail due to deadlocks

In my opinion, this kind of handling of transactions is pretty ugly.
The being said, we have issues with running into deadlocks on aur.al,
so this commit works against that immediate bug.

An ideal solution would be to deal with retrying transactions through
the `db.begin()` scope, so we wouldn't have to explicitly annotate
functions as "retry functions," which is what this commit does.

Closes #376

Signed-off-by: Kevin Morris <kevr@0cost.org>
This commit is contained in:
Kevin Morris 2022-09-13 12:47:52 -07:00
parent f450b5dfc7
commit ec3152014b
No known key found for this signature in database
GPG key ID: F7E46DED420788F3
16 changed files with 241 additions and 82 deletions

View file

@ -8,6 +8,7 @@ from aurweb.models.ssh_pub_key import get_fingerprint
from aurweb.util import strtobool
@db.retry_deadlock
def simple(
U: str = str(),
E: str = str(),
@ -42,6 +43,7 @@ def simple(
user.OwnershipNotify = strtobool(ON)
@db.retry_deadlock
def language(
L: str = str(),
request: Request = None,
@ -55,6 +57,7 @@ def language(
context["language"] = L
@db.retry_deadlock
def timezone(
TZ: str = str(),
request: Request = None,
@ -68,6 +71,7 @@ def timezone(
context["language"] = TZ
@db.retry_deadlock
def ssh_pubkey(PK: str = str(), user: models.User = None, **kwargs) -> None:
if not PK:
# If no pubkey is provided, wipe out any pubkeys the user
@ -101,12 +105,14 @@ def ssh_pubkey(PK: str = str(), user: models.User = None, **kwargs) -> None:
)
@db.retry_deadlock
def account_type(T: int = None, user: models.User = None, **kwargs) -> None:
if T is not None and (T := int(T)) != user.AccountTypeID:
with db.begin():
user.AccountTypeID = T
@db.retry_deadlock
def password(
P: str = str(),
request: Request = None,