dont select all user columns when updating

pull/173/head
Aevann 2023-07-27 22:46:29 +03:00
parent 4b83253861
commit 5cbb2c7428
2 changed files with 4 additions and 3 deletions

View File

@ -6,6 +6,7 @@ from flask import g
from pywebpush import webpush
import time
from sqlalchemy.sql import text
from sqlalchemy.orm import load_only
from files.classes import Comment, Notification, PushSubscription, Group
@ -154,7 +155,7 @@ def NOTIFY_USERS(text, v, oldtext=None, ghost=False, log_cost=None):
if cost > v.coins:
abort(403, f"You need {cost} coins to mention these ping groups!")
g.db.query(User).update({ User.coins: User.coins + 10 })
g.db.query(User).options(load_only(User.coins)).update({ User.coins: User.coins + 10 })
v.charge_account('coins', cost)
if log_cost:

View File

@ -129,9 +129,9 @@ def transfer_currency(v:User, username:str, currency_name:Literal['coins', 'mars
if not v.shadowbanned:
user_query = g.db.query(User).filter_by(id=receiver.id)
if currency_name == 'marseybux':
user_query.update({ User.marseybux: User.marseybux + amount - tax })
user_query.options(load_only(User.marseybux)).update({ User.marseybux: User.marseybux + amount - tax })
elif currency_name == 'coins':
user_query.update({ User.coins: User.coins + amount - tax })
user_query.options(load_only(User.coins)).update({ User.coins: User.coins + amount - tax })
else:
raise ValueError(f"Invalid currency '{currency_name}' got when transferring {amount} from {v.id} to {receiver.id}")
g.db.add(receiver)