more fixes
parent
e7dc7c5641
commit
fe2f1293f1
|
@ -490,6 +490,7 @@ class User(Base):
|
||||||
def referral_count(self):
|
def referral_count(self):
|
||||||
return len(self.referrals)
|
return len(self.referrals)
|
||||||
|
|
||||||
|
@lazy
|
||||||
def has_blocked(self, target):
|
def has_blocked(self, target):
|
||||||
return db.query(UserBlock).filter_by(user_id=self.id, target_id=target.id).one_or_none()
|
return db.query(UserBlock).filter_by(user_id=self.id, target_id=target.id).one_or_none()
|
||||||
|
|
||||||
|
|
|
@ -1,3 +1,5 @@
|
||||||
|
from flask import g
|
||||||
|
|
||||||
def lazy(f):
|
def lazy(f):
|
||||||
'''
|
'''
|
||||||
Prevents certain properties from having to be recomputed each time they are referenced
|
Prevents certain properties from having to be recomputed each time they are referenced
|
||||||
|
@ -6,7 +8,7 @@ def lazy(f):
|
||||||
o = args[0]
|
o = args[0]
|
||||||
if "_lazy" not in o.__dict__:
|
if "_lazy" not in o.__dict__:
|
||||||
o.__dict__["_lazy"] = {}
|
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"]:
|
if name not in o.__dict__["_lazy"]:
|
||||||
o.__dict__["_lazy"][name] = f(*args, **kwargs)
|
o.__dict__["_lazy"][name] = f(*args, **kwargs)
|
||||||
return o.__dict__["_lazy"][name]
|
return o.__dict__["_lazy"][name]
|
||||||
|
|
Loading…
Reference in New Issue