Remove unused polls code to reduce query volume.

Due to use of Submission.{choices, options, bet_options} in realbody,
generating submission_listings resulted in extremely high volume of
SELECT queries.

In local testing with 6 posts, one of which had a poll with 2 options,
the removal of these calls reduced quantity of queries on the homepage
from 84 to 22.

Given that it was previously decided to remove the polls feature after
a regression while adding comment filtering, the remaining dead code
paths for polls were also removed.
This commit is contained in:
TLSM 2022-09-05 03:53:25 -04:00 committed by Ben Rog-Wilhelm
parent cf9819ca5b
commit dbaf0a1bfd
10 changed files with 8 additions and 359 deletions

View file

@ -166,54 +166,6 @@ def remove_admin(v, username):
g.db.commit()
return {"message": "Admin removed!"}
@app.post("/distribute/<comment>")
@limiter.limit("1/second;30/minute;200/hour;1000/day")
@admin_level_required(3)
def distribute(v, comment):
autobetter = g.db.query(User).filter_by(id=AUTOBETTER_ID).one_or_none()
if autobetter.coins == 0: return {"error": "@AutoBetter has 0 coins"}
try: comment = int(comment)
except: abort(400)
post = g.db.query(Comment.parent_submission).filter_by(id=comment).one_or_none()[0]
post = g.db.query(Submission).filter_by(id=post).one_or_none()
pool = 0
for option in post.bet_options: pool += option.upvotes
pool *= 200
autobetter.coins -= pool
if autobetter.coins < 0: autobetter.coins = 0
g.db.add(autobetter)
votes = g.db.query(CommentVote).filter_by(comment_id=comment)
coinsperperson = int(pool / votes.count())
cid = notif_comment(f"You won {coinsperperson} coins betting on [{post.title}]({post.shortlink}) :marseyparty:")
for vote in votes:
u = vote.user
u.coins += coinsperperson
add_notif(cid, u.id)
cid = notif_comment(f"You lost the 200 coins you bet on [{post.title}]({post.shortlink}) :marseylaugh:")
cids = [x.id for x in post.bet_options]
cids.remove(comment)
votes = g.db.query(CommentVote).filter(CommentVote.comment_id.in_(cids)).all()
for vote in votes: add_notif(cid, vote.user.id)
post.body += '\n\nclosed'
g.db.add(post)
ma = ModAction(
kind="distribute",
user_id=v.id,
target_comment_id=comment
)
g.db.add(ma)
g.db.commit()
return {"message": f"Each winner has received {coinsperperson} coins!"}
@app.post("/@<username>/delete_note/<id>")
@admin_level_required(3)
def delete_note(v,username,id):