add more @lazy to functions

remotes/1693045480750635534/spooky-22
Aevann1 2022-06-23 18:36:39 +02:00
parent 39cf7fc48b
commit ceb72a470c
3 changed files with 16 additions and 3 deletions

View File

@ -122,13 +122,14 @@ class Comment(Base):
def choices(self):
return self.child_comments.filter_by(author_id=AUTOCHOICE_ID).order_by(Comment.id).all()
@lazy
def total_poll_voted(self, v):
if v:
for option in self.options:
if option.poll_voted(v): return True
return False
@lazy
def total_choice_voted(self, v):
if v:
return g.db.query(CommentVote).filter(CommentVote.user_id == v.id, CommentVote.comment_id.in_([x.id for x in self.choices])).all()
@ -321,6 +322,7 @@ class Comment(Base):
return data
@lazy
def award_count(self, kind):
return len([x for x in self.awards if x.kind == kind])
@ -354,7 +356,6 @@ class Comment(Base):
return data
@property
@lazy
def json(self):
data=self.json_core
@ -371,6 +372,7 @@ class Comment(Base):
return data
@lazy
def realbody(self, v):
if self.post and self.post.club and not (v and (v.paid_dues or v.id in [self.author_id, self.post.author_id])): return f"<p>{CC} ONLY</p>"
@ -435,6 +437,7 @@ class Comment(Base):
return body
@lazy
def plainbody(self, v):
if self.post and self.post.club and not (v and (v.paid_dues or v.id in [self.author_id, self.post.author_id])): return f"<p>{CC} ONLY</p>"

View File

@ -117,17 +117,20 @@ class Submission(Base):
def bet_options(self):
return g.db.query(Comment).filter_by(parent_submission = self.id, author_id = AUTOBETTER_ID, level=1).all()
@lazy
def total_poll_voted(self, v):
if v:
for option in self.options:
if option.poll_voted(v): return True
return False
@lazy
def total_choice_voted(self, v):
if v and self.choices:
return g.db.query(CommentVote).filter(CommentVote.user_id == v.id, CommentVote.comment_id.in_([x.id for x in self.choices])).all()
return False
@lazy
def total_bet_voted(self, v):
if "closed" in self.body.lower(): return True
if v:
@ -361,6 +364,7 @@ class Submission(Base):
return data
@lazy
def award_count(self, kind):
return len([x for x in self.awards if x.kind == kind])
@ -381,7 +385,7 @@ class Submission(Base):
return url
@lazy
def realbody(self, v):
if self.club and not (v and (v.paid_dues or v.id == self.author_id)): return f"<p>{CC} ONLY</p>"
@ -443,6 +447,7 @@ class Submission(Base):
return body
@lazy
def plainbody(self, v):
if self.club and not (v and (v.paid_dues or v.id == self.author_id)): return f"<p>{CC} ONLY</p>"

View File

@ -256,9 +256,11 @@ class User(Base):
return return_value
@property
@lazy
def referral_count(self):
return len(self.referrals)
@lazy
def is_blocking(self, target):
return g.db.query(UserBlock).filter_by(user_id=self.id, target_id=target.id).one_or_none()
@ -358,6 +360,7 @@ class User(Base):
if not self.is_suspended: return None
return g.db.get(User, self.is_banned)
@lazy
def has_badge(self, badge_id):
return g.db.query(Badge).filter_by(user_id=self.id, badge_id=badge_id).one_or_none()
@ -564,6 +567,7 @@ class User(Base):
modded_subs = g.db.query(Mod.sub).filter_by(user_id=self.id).all()
return modded_subs
@lazy
def has_follower(self, user):
return g.db.query(Follow).filter_by(target_id=self.id, user_id=user.id).one_or_none()
@ -657,6 +661,7 @@ class User(Base):
@property
@lazy
def is_suspended(self):
return (self.is_banned and (self.unban_utc == 0 or self.unban_utc > time.time()))