restrict leaderboards added in last commit to ppl who created more than 10 objects to prevent the leaderboards from being clogged with literally-whos

master
Aevann 2023-09-15 17:30:50 +03:00
parent c7d09a5c0a
commit c88da1d94d
1 changed files with 2 additions and 2 deletions

View File

@ -186,10 +186,10 @@ class Leaderboard:
@classmethod @classmethod
def get_avg_upvotes_lb(cls, lb_criteria, v, users, limit, desc): def get_avg_upvotes_lb(cls, lb_criteria, v, users, limit, desc):
sq = g.db.query(lb_criteria.author_id, cls.avg_and_label(lb_criteria.upvotes, lb_criteria.author_id)).filter_by(deleted_utc=0).group_by(lb_criteria.author_id).subquery() sq = g.db.query(lb_criteria.author_id, cls.avg_and_label(lb_criteria.upvotes, lb_criteria.author_id)).filter_by(deleted_utc=0).group_by(lb_criteria.author_id).having(func.count(lb_criteria.author_id) >= 10).subquery()
leaderboard = g.db.query(User, sq.c.avg).join(User, User.id == sq.c.author_id).order_by(sq.c.avg.desc()) leaderboard = g.db.query(User, sq.c.avg).join(User, User.id == sq.c.author_id).order_by(sq.c.avg.desc())
sq = g.db.query(lb_criteria.author_id, cls.avg_and_label(lb_criteria.upvotes, lb_criteria.author_id), cls.rank_filtered_rank_label_by_desc_avg(lb_criteria.upvotes, lb_criteria.author_id)).filter_by(deleted_utc=0).group_by(lb_criteria.author_id).subquery() sq = g.db.query(lb_criteria.author_id, cls.avg_and_label(lb_criteria.upvotes, lb_criteria.author_id), cls.rank_filtered_rank_label_by_desc_avg(lb_criteria.upvotes, lb_criteria.author_id)).filter_by(deleted_utc=0).group_by(lb_criteria.author_id).having(func.count(lb_criteria.author_id) >= 10).subquery()
position = g.db.query(sq.c.rank, sq.c.avg).join(User, User.id == sq.c.author_id).filter(sq.c.author_id == v.id).limit(1).one_or_none() position = g.db.query(sq.c.rank, sq.c.avg).join(User, User.id == sq.c.author_id).filter(sq.c.author_id == v.id).limit(1).one_or_none()
if not position: position = (leaderboard.count() + 1, 0) if not position: position = (leaderboard.count() + 1, 0)
leaderboard = leaderboard.limit(limit).all() leaderboard = leaderboard.limit(limit).all()