diff --git a/files/classes/submission.py b/files/classes/submission.py index a33aad78d..da41e425b 100644 --- a/files/classes/submission.py +++ b/files/classes/submission.py @@ -70,11 +70,11 @@ class Submission(Base): embed_url = Column(String) new = Column(Boolean) - author = relationship("User", primaryjoin="Submission.author_id==User.id") + author = relationship("User", primaryjoin="Submission.author_id==User.id", lazy="joined") oauth_app = relationship("OauthApp", viewonly=True) approved_by = relationship("User", uselist=False, primaryjoin="Submission.is_approved==User.id", viewonly=True) - awards = relationship("AwardRelationship", order_by="AwardRelationship.awarded_utc.desc()", viewonly=True) - reports = relationship("Flag", viewonly=True) + awards = relationship("AwardRelationship", order_by="AwardRelationship.awarded_utc.desc()", lazy="joined", viewonly=True) + flags = relationship("Flag", order_by="Flag.created_utc", lazy="joined", viewonly=True) comments = relationship("Comment", primaryjoin="Comment.parent_submission==Submission.id") subr = relationship("Sub", primaryjoin="foreign(Submission.sub)==remote(Sub.name)", viewonly=True) @@ -93,15 +93,6 @@ class Submission(Base): if self.downvotes > 5 and 0.25 < self.upvotes / self.downvotes < 4: return True return False - @lazy - def flags(self, v): - flags = g.db.query(Flag).filter_by(post_id=self.id).order_by(Flag.created_utc).all() - if not (v and (v.shadowbanned or v.admin_level >= 2)): - for flag in flags: - if flag.user.shadowbanned: - flags.remove(flag) - return flags - @property @lazy def options(self): @@ -287,7 +278,7 @@ class Submission(Base): @lazy def json_raw(self): flags = {} - for f in self.flags(None): flags[f.user.username] = f.reason + for f in self.flags: flags[f.user.username] = f.reason data = {'author_name': self.author_name if self.author else '', 'permalink': self.permalink, @@ -506,4 +497,4 @@ class Submission(Base): @lazy def active_flags(self, v): - return len(self.flags(v)) \ No newline at end of file + return len(self.flags) \ No newline at end of file diff --git a/files/classes/user.py b/files/classes/user.py index f1626aab5..739168fdc 100644 --- a/files/classes/user.py +++ b/files/classes/user.py @@ -135,7 +135,7 @@ class User(Base): total_held_lottery_tickets = Column(Integer, default=0) total_lottery_winnings = Column(Integer, default=0) - badges = relationship("Badge", order_by="Badge.created_utc", viewonly=True) + badges = relationship("Badge", order_by="Badge.created_utc", lazy="joined", viewonly=True) subscriptions = relationship("Subscription", viewonly=True) following = relationship("Follow", primaryjoin="Follow.user_id==User.id", viewonly=True) followers = relationship("Follow", primaryjoin="Follow.target_id==User.id", viewonly=True) diff --git a/files/routes/admin.py b/files/routes/admin.py index 71d6267b0..5536c30cb 100644 --- a/files/routes/admin.py +++ b/files/routes/admin.py @@ -430,7 +430,7 @@ def reported_posts(v): listing = g.db.query(Submission).filter_by( is_approved=None, is_banned=False - ).join(Submission.reports).order_by(Submission.id.desc()).offset(25 * (page - 1)).limit(26) + ).join(Submission.flags).order_by(Submission.id.desc()).offset(25 * (page - 1)).limit(26) listing = [p.id for p in listing] next_exists = len(listing) > 25 @@ -452,7 +452,7 @@ def reported_comments(v): ).filter_by( is_approved=None, is_banned=False - ).join(Comment.reports).order_by(Comment.id.desc()).offset(25 * (page - 1)).limit(26).all() + ).join(Comment.flags).order_by(Comment.id.desc()).offset(25 * (page - 1)).limit(26).all() listing = [c.id for c in listing] next_exists = len(listing) > 25 diff --git a/files/templates/submission.html b/files/templates/submission.html index 3574ce0f6..e781680dd 100644 --- a/files/templates/submission.html +++ b/files/templates/submission.html @@ -770,7 +770,7 @@ Reported by:

 						
diff --git a/files/templates/submission_listing.html b/files/templates/submission_listing.html
index bc839040c..90e7e28dd 100644
--- a/files/templates/submission_listing.html
+++ b/files/templates/submission_listing.html
@@ -72,7 +72,7 @@
 		 Reported by: