From 5cbb2c7428fd034efa5a7eb7cd3d0e2519a729bb Mon Sep 17 00:00:00 2001 From: Aevann Date: Thu, 27 Jul 2023 22:46:29 +0300 Subject: [PATCH] dont select all user columns when updating --- files/helpers/alerts.py | 3 ++- files/routes/users.py | 4 ++-- 2 files changed, 4 insertions(+), 3 deletions(-) diff --git a/files/helpers/alerts.py b/files/helpers/alerts.py index f607efc67..ea7e3df7e 100644 --- a/files/helpers/alerts.py +++ b/files/helpers/alerts.py @@ -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: diff --git a/files/routes/users.py b/files/routes/users.py index 351d45643..98ba0a6a7 100644 --- a/files/routes/users.py +++ b/files/routes/users.py @@ -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)