eliminate unnecessary db locks now that 1-second ratelimiting is universal (they cause timeouts sometimes)

master
Aevann 2023-06-07 06:51:59 +03:00
parent 9cd64d8595
commit 06288f1c3e
1 changed files with 7 additions and 8 deletions

View File

@ -203,9 +203,9 @@ class User(Base):
return
if currency == 'coins':
g.db.query(User).filter(User.id == self.id).update({ User.coins: User.coins + amount })
self.coins += amount
else:
g.db.query(User).filter(User.id == self.id).update({ User.marseybux: User.marseybux + amount })
self.marseybux += amount
g.db.flush()
@ -221,14 +221,14 @@ class User(Base):
account_balance = in_db.coins
if not should_check_balance or account_balance >= amount:
g.db.query(User).filter(User.id == self.id).update({ User.coins: User.coins - amount })
self.coins -= amount
succeeded = True
charged_coins = amount
elif currency == 'marseybux':
account_balance = in_db.marseybux
if not should_check_balance or account_balance >= amount:
g.db.query(User).filter(User.id == self.id).update({ User.marseybux: User.marseybux - amount })
self.marseybux -= amount
succeeded = True
elif currency == 'combined':
if in_db.marseybux >= amount:
@ -240,10 +240,9 @@ class User(Base):
if subtracted_coins > in_db.coins:
return (False, 0)
g.db.query(User).filter(User.id == self.id).update({
User.marseybux: User.marseybux - subtracted_mbux,
User.coins: User.coins - subtracted_coins,
})
self.coins -= subtracted_coins
self.marseybux -= subtracted_mbux
succeeded = True
charged_coins = subtracted_coins