diff --git a/files/classes/user.py b/files/classes/user.py index e7fedbecb..d820522d1 100644 --- a/files/classes/user.py +++ b/files/classes/user.py @@ -158,6 +158,7 @@ class User(Base): marsify = Column(Integer, default=0) rainbow = Column(Integer, default=0) spider = Column(Integer, default=0) + lifetimedonated = Column(Integer, default=0) blacklisted_by = Column(Integer, ForeignKey("users.id")) if IS_FISTMAS(): @@ -180,8 +181,6 @@ class User(Base): sub_mods = relationship("Mod", primaryjoin="User.id == Mod.user_id", lazy="raise") sub_exiles = relationship("Exile", primaryjoin="User.id == Exile.user_id", lazy="raise") - lifetimedonated = deferred(Column(Integer, server_default=FetchedValue())) - def __init__(self, **kwargs): if "password" in kwargs: @@ -253,11 +252,6 @@ class User(Base): return (succeeded, charged_coins) - @property - @lazy - def lifetime_donated(self): - return self.lifetimedonated or 0 - @property @lazy def num_of_bought_awards(self): diff --git a/files/routes/users.py b/files/routes/users.py index e818ca328..0b8582e50 100644 --- a/files/routes/users.py +++ b/files/routes/users.py @@ -81,25 +81,27 @@ def claim_rewards_all_users(): for x in range(22, badge_id+1): badge_grant(badge_id=x, user=user) - if user.lifetime_donated >= 100: + user.lifetimedonated = g.db.query(func.sum(Transaction.amount)).filter_by(email=user.email).scalar() + + if user.lifetimedonated >= 100: badge_grant(badge_id=257, user=user) - if user.lifetime_donated >= 500: + if user.lifetimedonated >= 500: badge_grant(badge_id=258, user=user) - if user.lifetime_donated >= 2500: + if user.lifetimedonated >= 2500: badge_grant(badge_id=259, user=user) - if user.lifetime_donated >= 5000: + if user.lifetimedonated >= 5000: badge_grant(badge_id=260, user=user) - if user.lifetime_donated >= 10000: + if user.lifetimedonated >= 10000: badge_grant(badge_id=261, user=user) print(f'@{user.username} rewards claimed successfully!', flush=True) - # for user in g.db.query(User).options(load_only(User.id)).order_by(User.lifetimedonated.desc()).limit(10).all(): - # badge_grant(badge_id=294, user=user) + for user in g.db.query(User).options(load_only(User.id)).order_by(User.lifetimedonated.desc()).limit(10).all(): + badge_grant(badge_id=294, user=user) def transfer_currency(v, username, currency_name, apply_tax): MIN_CURRENCY_TRANSFER = 100 diff --git a/files/templates/admin/patrons.html b/files/templates/admin/patrons.html index 70076d105..66ae50825 100644 --- a/files/templates/admin/patrons.html +++ b/files/templates/admin/patrons.html @@ -20,7 +20,7 @@ {% endif %} -
Coins spent on hats: {{u.coins_spent_on_hats}}
{% if v and (v.id == u.id or v.admin_level >= PERMS['VIEW_PATRONS']) %} -Lifetime donated: ${{u.lifetime_donated}} (shown to you only)
+Lifetime donated: ${{u.lifetimedonated}} (shown to you only)
{% endif %}Total award discount: {{u.formatted_discount}}
@@ -512,7 +512,7 @@Coins spent on hats: {{u.coins_spent_on_hats}}
{% if v and (v.id == u.id or v.admin_level >= PERMS['VIEW_PATRONS']) %} -Lifetime donated: ${{u.lifetime_donated}} (shown to you only)
+Lifetime donated: ${{u.lifetimedonated}} (shown to you only)
{% endif %}Total award discount: {{u.formatted_discount}}
diff --git a/migrations/20230801-move-lifetimedonated-to-column.sql b/migrations/20230801-move-lifetimedonated-to-column.sql new file mode 100644 index 000000000..d80058f7d --- /dev/null +++ b/migrations/20230801-move-lifetimedonated-to-column.sql @@ -0,0 +1,3 @@ +alter table users add column lifetimedonated int not null default 0; +alter table users alter column lifetimedonated drop default; +update users set lifetimedonated=(select sum(amount) from transactions where transactions.email = users.email) where (select sum(amount) from transactions where transactions.email = users.email)>0;