master
Aevann1 2021-09-27 23:46:35 +02:00
parent 4dfb091d79
commit 33a7ebf0dc
8 changed files with 40 additions and 37 deletions

View File

@ -268,11 +268,11 @@ def image_posts_listing(v):
try: page = int(request.values.get('page', 1))
except: page = 1
posts = g.db.query(Submission).order_by(Submission.id.desc())
posts = g.db.query(Submission.id).order_by(Submission.id.desc())
firstrange = 25 * (page - 1)
secondrange = firstrange+26
posts = [x.id for x in posts if x.is_image][firstrange:secondrange]
posts = [x[0] for x in posts if x.is_image][firstrange:secondrange]
next_exists = (len(posts) > 25)
posts = get_posts(posts[:25], v=v)

View File

@ -564,10 +564,10 @@ def api_comment(v):
cache.delete_memoized(comment_idlist)
v.comment_count = v.comments.filter(Comment.parent_submission != None).filter_by(is_banned=False, deleted_utc=0).count()
v.comment_count = g.db.query(Comment.id).options(lazyload('*')).filter(Comment.author_id == v.id, Comment.parent_submission != None).filter_by(is_banned=False, deleted_utc=0).count()
g.db.add(v)
parent_post.comment_count = g.db.query(Comment).options(lazyload('*')).filter_by(parent_submission=parent_post.id).count()
parent_post.comment_count = g.db.query(Comment.id).options(lazyload('*')).filter_by(parent_submission=parent_post.id).count()
g.db.add(parent_post)
c.voted = 1

View File

@ -346,8 +346,8 @@ def sign_up_post(v):
g.db.add(ref_user)
id_1 = g.db.query(User).options(lazyload('*')).filter_by(id=6).count()
users_count = g.db.query(User).count() #paranoid
id_1 = g.db.query(User.id).options(lazyload('*')).filter_by(id=6).count()
users_count = g.db.query(User.id).count() #paranoid
if id_1 == 0 and users_count < 6: admin_level=6
else: admin_level=0

View File

@ -352,7 +352,10 @@ def edit_post(pid, v):
user = g.db.query(User).options(lazyload('*')).filter_by(username=username).first()
if user and not v.any_block_exists(user) and user.id != v.id: notify_users.add(user)
for x in notify_users: send_notification(NOTIFICATIONS_ACCOUNT, x, f"@{v.username} has mentioned you: https://{site}{p.permalink}")
message = f"@{v.username} has mentioned you: https://{site}{p.permalink}"
for x in notify_users:
existing = g.db.query(Comment).options(lazyload('*')).filter(Comment.author_id == NOTIFICATIONS_ACCOUNT, Comment.sentto == x.id, Comment.body == message).first()
if not existing: send_notification(NOTIFICATIONS_ACCOUNT, x, message)
if title != p.title or body != p.body:

View File

@ -753,7 +753,7 @@ def settings_name_change(v):
def settings_song_change(v):
song=request.values.get("song").strip()
if song == "" and v.song and path.isfile(f"/songs/{v.song}.mp3") and g.db.query(User).options(lazyload('*')).filter_by(song=v.song).count() == 1:
if song == "" and v.song and path.isfile(f"/songs/{v.song}.mp3") and g.db.query(User.id).options(lazyload('*')).filter_by(song=v.song).count() == 1:
os.remove(f"/songs/{v.song}.mp3")
v.song=None
g.db.add(v)
@ -798,7 +798,7 @@ def settings_song_change(v):
error=f"Duration of the video must not exceed 10 minutes.")
if v.song and path.isfile(f"/songs/{v.song}.mp3") and g.db.query(User).options(lazyload('*')).filter_by(song=v.song).count() == 1:
if v.song and path.isfile(f"/songs/{v.song}.mp3") and g.db.query(User.id).options(lazyload('*')).filter_by(song=v.song).count() == 1:
os.remove(f"/songs/{v.song}.mp3")
ydl_opts = {

View File

@ -34,29 +34,29 @@ def participation_stats(v):
day = now - 86400
data = {"valid_users": g.db.query(User).count(),
"private_users": g.db.query(User).options(lazyload('*')).filter_by(is_private=True).count(),
"banned_users": g.db.query(User).options(lazyload('*')).filter(User.is_banned > 0).count(),
"verified_email_users": g.db.query(User).options(lazyload('*')).filter_by(is_activated=True).count(),
data = {"valid_users": g.db.query(User.id).count(),
"private_users": g.db.query(User.id).options(lazyload('*')).filter_by(is_private=True).count(),
"banned_users": g.db.query(User.id).options(lazyload('*')).filter(User.is_banned > 0).count(),
"verified_email_users": g.db.query(User.id).options(lazyload('*')).filter_by(is_activated=True).count(),
"total_coins": g.db.query(func.sum(User.coins)).scalar(),
"signups_last_24h": g.db.query(User).options(lazyload('*')).filter(User.created_utc > day).count(),
"total_posts": g.db.query(Submission).count(),
"signups_last_24h": g.db.query(User.id).options(lazyload('*')).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).options(lazyload('*')).filter_by(is_banned=False).filter(Submission.deleted_utc == 0).count(),
"removed_posts": g.db.query(Submission).options(lazyload('*')).filter_by(is_banned=True).count(),
"deleted_posts": g.db.query(Submission).options(lazyload('*')).filter(Submission.deleted_utc > 0).count(),
"posts_last_24h": g.db.query(Submission).options(lazyload('*')).filter(Submission.created_utc > day).count(),
"total_comments": g.db.query(Comment).count(),
"listed_posts": g.db.query(Submission.id).options(lazyload('*')).filter_by(is_banned=False).filter(Submission.deleted_utc == 0).count(),
"removed_posts": g.db.query(Submission.id).options(lazyload('*')).filter_by(is_banned=True).count(),
"deleted_posts": g.db.query(Submission.id).options(lazyload('*')).filter(Submission.deleted_utc > 0).count(),
"posts_last_24h": g.db.query(Submission.id).options(lazyload('*')).filter(Submission.created_utc > day).count(),
"total_comments": g.db.query(Comment.id).count(),
"commenting_users": g.db.query(Comment.author_id).distinct().count(),
"removed_comments": g.db.query(Comment).options(lazyload('*')).filter_by(is_banned=True).count(),
"deleted_comments": g.db.query(Comment).options(lazyload('*')).filter(Comment.deleted_utc>0).count(),
"comments_last_24h": g.db.query(Comment).options(lazyload('*')).filter(Comment.created_utc > day).count(),
"post_votes": g.db.query(Vote).count(),
"removed_comments": g.db.query(Comment.id).options(lazyload('*')).filter_by(is_banned=True).count(),
"deleted_comments": g.db.query(Comment.id).options(lazyload('*')).filter(Comment.deleted_utc>0).count(),
"comments_last_24h": g.db.query(Comment.id).options(lazyload('*')).filter(Comment.created_utc > day).count(),
"post_votes": g.db.query(Vote.id).count(),
"post_voting_users": g.db.query(Vote.user_id).distinct().count(),
"comment_votes": g.db.query(CommentVote).count(),
"comment_votes": g.db.query(CommentVote.id).count(),
"comment_voting_users": g.db.query(CommentVote.user_id).distinct().count(),
"total_awards": g.db.query(AwardRelationship).count(),
"awards_given": g.db.query(AwardRelationship).options(lazyload('*')).filter(or_(AwardRelationship.submission_id != None, AwardRelationship.comment_id != None)).count()
"total_awards": g.db.query(AwardRelationship.id).count(),
"awards_given": g.db.query(AwardRelationship.id).options(lazyload('*')).filter(or_(AwardRelationship.submission_id != None, AwardRelationship.comment_id != None)).count()
}
@ -94,11 +94,11 @@ def cached_chart():
daily_times = [time.strftime("%d", time.gmtime(day_cutoffs[i + 1])) for i in range(len(day_cutoffs) - 1)][2:][::-1]
daily_signups = [g.db.query(User).options(lazyload('*')).filter(User.created_utc < day_cutoffs[i], User.created_utc > day_cutoffs[i + 1]).count() for i in range(len(day_cutoffs) - 1)][2:][::-1]
daily_signups = [g.db.query(User.id).options(lazyload('*')).filter(User.created_utc < day_cutoffs[i], User.created_utc > day_cutoffs[i + 1]).count() for i in range(len(day_cutoffs) - 1)][2:][::-1]
post_stats = [g.db.query(Submission).options(lazyload('*')).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)][2:][::-1]
post_stats = [g.db.query(Submission.id).options(lazyload('*')).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)][2:][::-1]
comment_stats = [g.db.query(Comment).options(lazyload('*')).filter(Comment.created_utc < day_cutoffs[i], Comment.created_utc > day_cutoffs[i + 1],Comment.is_banned == False, Comment.author_id != 1).count() for i in range(len(day_cutoffs) - 1)][2:][::-1]
comment_stats = [g.db.query(Comment.id).options(lazyload('*')).filter(Comment.created_utc < day_cutoffs[i], Comment.created_utc > day_cutoffs[i + 1],Comment.is_banned == False, Comment.author_id != 1).count() for i in range(len(day_cutoffs) - 1)][2:][::-1]
# create multiple charts
signup_chart = plt.subplot2grid((20, 4), (0, 0), rowspan=5, colspan=4)

View File

@ -558,7 +558,7 @@ def u_username_comments(username, v=None):
t=request.values.get("t","all")
comments = u.comments.options(lazyload('*')).filter(Comment.parent_submission != None)
comments = g.db.query(Comment.id).options(lazyload('*')).filter(Comment.author_id == u.id, Comment.parent_submission != None)
if (not v) or (v.id != u.id and v.admin_level == 0):
comments = comments.filter(Comment.deleted_utc == 0)
@ -636,7 +636,7 @@ def follow_user(username, v):
try: g.db.flush()
except: g.db.rollback()
target.stored_subscriber_count = g.db.query(Follow).options(lazyload('*')).filter_by(target_id=target.id).count()
target.stored_subscriber_count = g.db.query(Follow.id).options(lazyload('*')).filter_by(target_id=target.id).count()
g.db.add(target)
existing = g.db.query(Notification).options(lazyload('*')).filter_by(followsender=v.id, user_id=target.id).first()
@ -662,7 +662,7 @@ def unfollow_user(username, v):
g.db.delete(follow)
g.db.flush()
target.stored_subscriber_count = g.db.query(Follow).options(lazyload('*')).filter_by(target_id=target.id).count()
target.stored_subscriber_count = g.db.query(Follow.id).options(lazyload('*')).filter_by(target_id=target.id).count()
g.db.add(target)
existing = g.db.query(Notification).options(lazyload('*')).filter_by(unfollowsender=v.id, user_id=target.id).first()

View File

@ -98,8 +98,8 @@ def api_vote_post(post_id, new, v):
try:
g.db.flush()
post.upvotes = g.db.query(Vote).options(lazyload('*')).filter_by(submission_id=post.id, vote_type=1).count()
post.downvotes = g.db.query(Vote).options(lazyload('*')).filter_by(submission_id=post.id, vote_type=-1).count()
post.upvotes = g.db.query(Vote.id).options(lazyload('*')).filter_by(submission_id=post.id, vote_type=1).count()
post.downvotes = g.db.query(Vote.id).options(lazyload('*')).filter_by(submission_id=post.id, vote_type=-1).count()
g.db.add(post)
g.db.commit()
except: g.db.rollback()
@ -154,8 +154,8 @@ def api_vote_comment(comment_id, new, v):
try:
g.db.flush()
comment.upvotes = g.db.query(CommentVote).options(lazyload('*')).filter_by(comment_id=comment.id, vote_type=1).count()
comment.downvotes = g.db.query(CommentVote).options(lazyload('*')).filter_by(comment_id=comment.id, vote_type=-1).count()
comment.upvotes = g.db.query(CommentVote.id).options(lazyload('*')).filter_by(comment_id=comment.id, vote_type=1).count()
comment.downvotes = g.db.query(CommentVote.id).options(lazyload('*')).filter_by(comment_id=comment.id, vote_type=-1).count()
g.db.add(comment)
g.db.commit()
except: g.db.rollback()