diff --git a/files/classes/user.py b/files/classes/user.py
index e940e6656..dcaeb7b1d 100644
--- a/files/classes/user.py
+++ b/files/classes/user.py
@@ -322,7 +322,7 @@ class User(Base):
@property
@lazy
def follow_count(self):
- return g.db.query(Follow.target_id).filter_by(user_id=self.id).count()
+ return g.db.query(Follow).filter_by(user_id=self.id).count()
@property
@lazy
@@ -422,7 +422,7 @@ class User(Base):
@lazy
def modaction_num(self):
if self.admin_level < 2: return 0
- return g.db.query(ModAction.id).filter_by(user_id=self.id).count()
+ return g.db.query(ModAction).filter_by(user_id=self.id).count()
@property
@lazy
@@ -437,12 +437,12 @@ class User(Base):
@property
@lazy
def post_notifications_count(self):
- return g.db.query(Notification.user_id).join(Comment).filter(Notification.user_id == self.id, Notification.read == False, Comment.author_id == AUTOJANNY_ID).count()
+ return g.db.query(Notification).join(Comment).filter(Notification.user_id == self.id, Notification.read == False, Comment.author_id == AUTOJANNY_ID).count()
@property
@lazy
def reddit_notifications_count(self):
- return g.db.query(Notification.user_id).join(Comment).filter(Notification.user_id == self.id, Notification.read == False, Comment.is_banned == False, Comment.deleted_utc == 0, Comment.body_html.like('%
New site mention: 2:
if v.admin_level > 2:
post.stickied = v.username
diff --git a/files/routes/comments.py b/files/routes/comments.py
index fc325c600..a7acc315d 100644
--- a/files/routes/comments.py
+++ b/files/routes/comments.py
@@ -282,7 +282,7 @@ def api_comment(v):
g.db.add(marsey)
g.db.flush()
- all_by_author = g.db.query(Marsey.author_id).filter_by(author_id=user.id).count()
+ all_by_author = g.db.query(Marsey).filter_by(author_id=user.id).count()
if all_by_author >= 10 and not user.has_badge(16):
new_badge = Badge(badge_id=16, user_id=user.id)
@@ -636,7 +636,7 @@ def api_comment(v):
cache.delete_memoized(comment_idlist)
- v.comment_count = g.db.query(Comment.id).filter(Comment.author_id == v.id, Comment.parent_submission != None).filter_by(is_banned=False, deleted_utc=0).count()
+ v.comment_count = g.db.query(Comment).filter(Comment.author_id == v.id, Comment.parent_submission != None).filter_by(is_banned=False, deleted_utc=0).count()
g.db.add(v)
c.voted = 1
diff --git a/files/routes/login.py b/files/routes/login.py
index c63006ab6..df632640b 100644
--- a/files/routes/login.py
+++ b/files/routes/login.py
@@ -315,8 +315,8 @@ def sign_up_post(v):
ref_id = int(request.values.get("referred_by", 0))
- id_1 = g.db.query(User.id).filter_by(id=9).count()
- users_count = g.db.query(User.id).count()
+ id_1 = g.db.query(User).filter_by(id=9).count()
+ users_count = g.db.query(User).count()
if id_1 == 0 and users_count == 8:
admin_level=3
session["history"] = []
diff --git a/files/routes/posts.py b/files/routes/posts.py
index 2f0b1e0ed..6989f5a54 100644
--- a/files/routes/posts.py
+++ b/files/routes/posts.py
@@ -229,13 +229,13 @@ def post_id(pid, anything=None, v=None, sub=None):
for comment in comments:
comments2.append(comment)
ids.add(comment.id)
- count += g.db.query(Comment.id).filter_by(parent_submission=post.id, top_comment_id=comment.id).count() + 1
+ count += g.db.query(Comment).filter_by(parent_submission=post.id, top_comment_id=comment.id).count() + 1
if count > 50: break
else:
for comment in comments:
comments2.append(comment)
ids.add(comment.id)
- count += g.db.query(Comment.id).filter_by(parent_submission=post.id, parent_comment_id=comment.id).count() + 1
+ count += g.db.query(Comment).filter_by(parent_submission=post.id, parent_comment_id=comment.id).count() + 1
if count > 10: break
if len(comments) == len(comments2): offset = 0
@@ -353,13 +353,13 @@ def viewmore(v, pid, sort, offset):
for comment in comments:
comments2.append(comment)
ids.add(comment.id)
- count += g.db.query(Comment.id).filter_by(parent_submission=post.id, top_comment_id=comment.id).count() + 1
+ count += g.db.query(Comment).filter_by(parent_submission=post.id, top_comment_id=comment.id).count() + 1
if count > 50: break
else:
for comment in comments:
comments2.append(comment)
ids.add(comment.id)
- count += g.db.query(Comment.id).filter_by(parent_submission=post.id, parent_comment_id=comment.id).count() + 1
+ count += g.db.query(Comment).filter_by(parent_submission=post.id, parent_comment_id=comment.id).count() + 1
if count > 10: break
if len(comments) == len(comments2): offset = 0
@@ -1362,7 +1362,7 @@ def submit_post(v, sub=None):
post.comment_count += 1
post.replies = [c]
- v.post_count = g.db.query(Submission.id).filter_by(author_id=v.id, is_banned=False, deleted_utc=0).count()
+ v.post_count = g.db.query(Submission).filter_by(author_id=v.id, is_banned=False, deleted_utc=0).count()
g.db.add(v)
if v.id == PIZZASHILL_ID:
diff --git a/files/routes/settings.py b/files/routes/settings.py
index 87e90323f..6964efc66 100644
--- a/files/routes/settings.py
+++ b/files/routes/settings.py
@@ -797,7 +797,7 @@ def settings_song_change(v):
song=request.values.get("song").strip()
if song == "" and v.song:
- if path.isfile(f"/songs/{v.song}.mp3") and g.db.query(User.id).filter_by(song=v.song).count() == 1:
+ if path.isfile(f"/songs/{v.song}.mp3") and g.db.query(User).filter_by(song=v.song).count() == 1:
os.remove(f"/songs/{v.song}.mp3")
v.song = None
g.db.add(v)
@@ -836,7 +836,7 @@ def settings_song_change(v):
return render_template("settings_profile.html", v=v, error="Duration of the video must not exceed 15 minutes.")
- if v.song and path.isfile(f"/songs/{v.song}.mp3") and g.db.query(User.id).filter_by(song=v.song).count() == 1:
+ if v.song and path.isfile(f"/songs/{v.song}.mp3") and g.db.query(User).filter_by(song=v.song).count() == 1:
os.remove(f"/songs/{v.song}.mp3")
ydl_opts = {
diff --git a/files/routes/static.py b/files/routes/static.py
index 404d4eadd..cdffde3ec 100644
--- a/files/routes/static.py
+++ b/files/routes/static.py
@@ -86,42 +86,42 @@ def stats(site=None):
active_users = set(posters) | set(commenters) | set(voters) | set(commentvoters)
- stats = {"marseys": g.db.query(Marsey.name).count(),
- "users": g.db.query(User.id).count(),
- "private users": g.db.query(User.id).filter_by(is_private=True).count(),
- "banned users": g.db.query(User.id).filter(User.is_banned > 0).count(),
- "verified email users": g.db.query(User.id).filter_by(is_activated=True).count(),
+ stats = {"marseys": g.db.query(Marsey).count(),
+ "users": g.db.query(User).count(),
+ "private users": g.db.query(User).filter_by(is_private=True).count(),
+ "banned users": g.db.query(User).filter(User.is_banned > 0).count(),
+ "verified email users": g.db.query(User).filter_by(is_activated=True).count(),
"coins in circulation": g.db.query(func.sum(User.coins)).scalar(),
"total shop sales": g.db.query(func.sum(User.coins_spent)).scalar(),
- "signups last 24h": g.db.query(User.id).filter(User.created_utc > day).count(),
- "total posts": g.db.query(Submission.id).count(),
- "posting users": g.db.query(Submission.author_id).distinct().count(),
- "listed posts": g.db.query(Submission.id).filter_by(is_banned=False).filter(Submission.deleted_utc == 0).count(),
- "removed posts (by admins)": g.db.query(Submission.id).filter_by(is_banned=True).count(),
- "deleted posts (by author)": g.db.query(Submission.id).filter(Submission.deleted_utc > 0).count(),
- "posts last 24h": g.db.query(Submission.id).filter(Submission.created_utc > day).count(),
- "total comments": g.db.query(Comment.id).filter(Comment.author_id.notin_((AUTOJANNY_ID,NOTIFICATIONS_ID))).count(),
- "commenting users": g.db.query(Comment.author_id).distinct().count(),
- "removed comments (by admins)": g.db.query(Comment.id).filter_by(is_banned=True).count(),
- "deleted comments (by author)": g.db.query(Comment.id).filter(Comment.deleted_utc > 0).count(),
- "comments last_24h": g.db.query(Comment.id).filter(Comment.created_utc > day, Comment.author_id.notin_((AUTOJANNY_ID,NOTIFICATIONS_ID))).count(),
- "post votes": g.db.query(Vote.submission_id).count(),
- "post voting users": g.db.query(Vote.user_id).distinct().count(),
- "comment votes": g.db.query(CommentVote.comment_id).count(),
- "comment voting users": g.db.query(CommentVote.user_id).distinct().count(),
- "total upvotes": g.db.query(Vote.submission_id).filter_by(vote_type=1).count() + g.db.query(CommentVote.comment_id).filter_by(vote_type=1).count(),
- "total downvotes": g.db.query(Vote.submission_id).filter_by(vote_type=-1).count() + g.db.query(CommentVote.comment_id).filter_by(vote_type=-1).count(),
- "total awards": g.db.query(AwardRelationship.id).count(),
- "awards given": g.db.query(AwardRelationship.id).filter(or_(AwardRelationship.submission_id != None, AwardRelationship.comment_id != None)).count(),
+ "signups last 24h": g.db.query(User).filter(User.created_utc > day).count(),
+ "total posts": g.db.query(Submission).count(),
+ "posting users": g.db.query(Submission).distinct().count(),
+ "listed posts": g.db.query(Submission).filter_by(is_banned=False).filter(Submission.deleted_utc == 0).count(),
+ "removed posts (by admins)": g.db.query(Submission).filter_by(is_banned=True).count(),
+ "deleted posts (by author)": g.db.query(Submission).filter(Submission.deleted_utc > 0).count(),
+ "posts last 24h": g.db.query(Submission).filter(Submission.created_utc > day).count(),
+ "total comments": g.db.query(Comment).filter(Comment.author_id.notin_((AUTOJANNY_ID,NOTIFICATIONS_ID))).count(),
+ "commenting users": g.db.query(Comment).distinct().count(),
+ "removed comments (by admins)": g.db.query(Comment).filter_by(is_banned=True).count(),
+ "deleted comments (by author)": g.db.query(Comment).filter(Comment.deleted_utc > 0).count(),
+ "comments last_24h": g.db.query(Comment).filter(Comment.created_utc > day, Comment.author_id.notin_((AUTOJANNY_ID,NOTIFICATIONS_ID))).count(),
+ "post votes": g.db.query(Vote).count(),
+ "post voting users": g.db.query(Vote).distinct().count(),
+ "comment votes": g.db.query(CommentVote).count(),
+ "comment voting users": g.db.query(CommentVote).distinct().count(),
+ "total upvotes": g.db.query(Vote).filter_by(vote_type=1).count() + g.db.query(CommentVote.comment_id).filter_by(vote_type=1).count(),
+ "total downvotes": g.db.query(Vote).filter_by(vote_type=-1).count() + g.db.query(CommentVote.comment_id).filter_by(vote_type=-1).count(),
+ "total awards": g.db.query(AwardRelationship).count(),
+ "awards given": g.db.query(AwardRelationship).filter(or_(AwardRelationship.submission_id != None, AwardRelationship.comment_id != None)).count(),
"users who posted, commented, or voted in the past 7 days": len(active_users),
}
if SITE_NAME == 'rDrama':
- furries1 = g.db.query(User.id).filter(User.house.like('Furry%')).count()
- femboys1 = g.db.query(User.id).filter(User.house.like('Femboy%')).count()
- vampires1 = g.db.query(User.id).filter(User.house.like('Vampire%')).count()
- racists1 = g.db.query(User.id).filter(User.house.like('Racist%')).count()
+ furries1 = g.db.query(User).filter(User.house.like('Furry%')).count()
+ femboys1 = g.db.query(User).filter(User.house.like('Femboy%')).count()
+ vampires1 = g.db.query(User).filter(User.house.like('Vampire%')).count()
+ racists1 = g.db.query(User).filter(User.house.like('Racist%')).count()
furries2 = g.db.query(func.sum(User.truecoins)).filter(User.house.like('Furry%')).scalar()
femboys2 = g.db.query(func.sum(User.truecoins)).filter(User.house.like('Femboy%')).scalar()
@@ -251,11 +251,11 @@ def cached_chart(kind, site):
daily_times = [time.strftime("%d/%m", time.gmtime(day_cutoffs[i + 1])) for i in range(len(day_cutoffs) - 1)][::-1]
- daily_signups = [g.db.query(User.id).filter(User.created_utc < day_cutoffs[i], User.created_utc > day_cutoffs[i + 1]).count() for i in range(len(day_cutoffs) - 1)][::-1]
+ daily_signups = [g.db.query(User).filter(User.created_utc < day_cutoffs[i], User.created_utc > day_cutoffs[i + 1]).count() for i in range(len(day_cutoffs) - 1)][::-1]
- post_stats = [g.db.query(Submission.id).filter(Submission.created_utc < day_cutoffs[i], Submission.created_utc > day_cutoffs[i + 1], Submission.is_banned == False).count() for i in range(len(day_cutoffs) - 1)][::-1]
+ post_stats = [g.db.query(Submission).filter(Submission.created_utc < day_cutoffs[i], Submission.created_utc > day_cutoffs[i + 1], Submission.is_banned == False).count() for i in range(len(day_cutoffs) - 1)][::-1]
- comment_stats = [g.db.query(Comment.id).filter(Comment.created_utc < day_cutoffs[i], Comment.created_utc > day_cutoffs[i + 1],Comment.is_banned == False, Comment.author_id.notin_((AUTOJANNY_ID,NOTIFICATIONS_ID))).count() for i in range(len(day_cutoffs) - 1)][::-1]
+ comment_stats = [g.db.query(Comment).filter(Comment.created_utc < day_cutoffs[i], Comment.created_utc > day_cutoffs[i + 1],Comment.is_banned == False, Comment.author_id.notin_((AUTOJANNY_ID,NOTIFICATIONS_ID))).count() for i in range(len(day_cutoffs) - 1)][::-1]
plt.rcParams["figure.figsize"] = (30, 20)
@@ -497,7 +497,7 @@ no = (21,22,23,24,25,26,27)
def badge_list(site):
badges = g.db.query(BadgeDef).filter(BadgeDef.id.notin_(no)).order_by(BadgeDef.id).all()
counts_raw = g.db.query(Badge.badge_id, func.count()).group_by(Badge.badge_id).all()
- users = g.db.query(User.id).count()
+ users = g.db.query(User).count()
counts = {}
for c in counts_raw:
diff --git a/files/routes/users.py b/files/routes/users.py
index 6380d1db8..0d7fee553 100644
--- a/files/routes/users.py
+++ b/files/routes/users.py
@@ -1075,7 +1075,7 @@ def follow_user(username, v):
g.db.add(new_follow)
g.db.flush()
- target.stored_subscriber_count = g.db.query(Follow.target_id).filter_by(target_id=target.id).count()
+ target.stored_subscriber_count = g.db.query(Follow).filter_by(target_id=target.id).count()
g.db.add(target)
send_notification(target.id, f"@{v.username} has followed you!")
@@ -1103,7 +1103,7 @@ def unfollow_user(username, v):
g.db.delete(follow)
g.db.flush()
- target.stored_subscriber_count = g.db.query(Follow.target_id).filter_by(target_id=target.id).count()
+ target.stored_subscriber_count = g.db.query(Follow).filter_by(target_id=target.id).count()
g.db.add(target)
send_notification(target.id, f"@{v.username} has unfollowed you!")
@@ -1126,7 +1126,7 @@ def remove_follow(username, v):
g.db.delete(follow)
g.db.flush()
- v.stored_subscriber_count = g.db.query(Follow.target_id).filter_by(target_id=v.id).count()
+ v.stored_subscriber_count = g.db.query(Follow).filter_by(target_id=v.id).count()
g.db.add(v)
send_repeatable_notification(target.id, f"@{v.username} has removed your follow!")
diff --git a/files/routes/votes.py b/files/routes/votes.py
index a8d8d657c..c2f4a66e6 100644
--- a/files/routes/votes.py
+++ b/files/routes/votes.py
@@ -105,9 +105,9 @@ def api_vote_post(post_id, new, v):
g.db.add(vote)
g.db.flush()
- post.upvotes = g.db.query(Vote.submission_id).filter_by(submission_id=post.id, vote_type=1).count()
- post.downvotes = g.db.query(Vote.submission_id).filter_by(submission_id=post.id, vote_type=-1).count()
- post.realupvotes = g.db.query(Vote.submission_id).filter_by(submission_id=post.id, real=True).count()
+ post.upvotes = g.db.query(Vote).filter_by(submission_id=post.id, vote_type=1).count()
+ post.downvotes = g.db.query(Vote).filter_by(submission_id=post.id, vote_type=-1).count()
+ post.realupvotes = g.db.query(Vote).filter_by(submission_id=post.id, real=True).count()
if post.author.progressivestack: post.realupvotes *= 2
g.db.add(post)
g.db.commit()
@@ -175,9 +175,9 @@ def api_vote_comment(comment_id, new, v):
g.db.add(vote)
g.db.flush()
- comment.upvotes = g.db.query(CommentVote.comment_id).filter_by(comment_id=comment.id, vote_type=1).count()
- comment.downvotes = g.db.query(CommentVote.comment_id).filter_by(comment_id=comment.id, vote_type=-1).count()
- comment.realupvotes = g.db.query(CommentVote.comment_id).filter_by(comment_id=comment.id, real=True).count()
+ comment.upvotes = g.db.query(CommentVote).filter_by(comment_id=comment.id, vote_type=1).count()
+ comment.downvotes = g.db.query(CommentVote).filter_by(comment_id=comment.id, vote_type=-1).count()
+ comment.realupvotes = g.db.query(CommentVote).filter_by(comment_id=comment.id, real=True).count()
if comment.author.progressivestack: comment.realupvotes *= 2
g.db.add(comment)
g.db.commit()
@@ -210,7 +210,7 @@ def api_vote_poll(comment_id, v):
g.db.add(vote)
g.db.flush()
- comment.upvotes = g.db.query(CommentVote.comment_id).filter_by(comment_id=comment.id, vote_type=1).count()
+ comment.upvotes = g.db.query(CommentVote).filter_by(comment_id=comment.id, vote_type=1).count()
g.db.add(comment)
g.db.commit()
return "", 204
@@ -268,12 +268,12 @@ def api_vote_choice(comment_id, v):
else: parent = comment.post
for vote in parent.total_choice_voted(v):
- vote.comment.upvotes = g.db.query(CommentVote.comment_id).filter_by(comment_id=vote.comment.id, vote_type=1).count() - 1
+ vote.comment.upvotes = g.db.query(CommentVote).filter_by(comment_id=vote.comment.id, vote_type=1).count() - 1
g.db.add(vote.comment)
g.db.delete(vote)
g.db.flush()
- comment.upvotes = g.db.query(CommentVote.comment_id).filter_by(comment_id=comment.id, vote_type=1).count()
+ comment.upvotes = g.db.query(CommentVote).filter_by(comment_id=comment.id, vote_type=1).count()
g.db.add(comment)
g.db.commit()
return "", 204
\ No newline at end of file