more fixes

pull/139/head
Aevann 2023-03-15 07:13:58 +02:00
parent e7dc7c5641
commit fe2f1293f1
2 changed files with 4 additions and 1 deletions

View File

@ -490,6 +490,7 @@ class User(Base):
def referral_count(self):
return len(self.referrals)
@lazy
def has_blocked(self, target):
return db.query(UserBlock).filter_by(user_id=self.id, target_id=target.id).one_or_none()

View File

@ -1,3 +1,5 @@
from flask import g
def lazy(f):
'''
Prevents certain properties from having to be recomputed each time they are referenced
@ -6,7 +8,7 @@ def lazy(f):
o = args[0]
if "_lazy" not in o.__dict__:
o.__dict__["_lazy"] = {}
name = f.__name__ + str(args) + str(kwargs),
name = f.__name__ + str(args) + str(kwargs) + g.nonce,
if name not in o.__dict__["_lazy"]:
o.__dict__["_lazy"][name] = f(*args, **kwargs)
return o.__dict__["_lazy"][name]