reducing query volume, #2

remotes/1693045480750635534/spooky-22
Aevann1 2022-06-26 03:11:02 +02:00
parent cd4b3b7d3b
commit cff34fb3a4
25 changed files with 5 additions and 173 deletions

View File

@ -94,6 +94,7 @@ def before_request():
@app.teardown_appcontext
def teardown_request(error):
if hasattr(g, 'db') and g.db:
g.db.commit()
g.db.close()
stdout.flush()

View File

@ -404,7 +404,6 @@ class Comment(Base):
if amount == 1:
self.upvotes += amount
g.db.add(self)
g.db.commit()
for c in self.options:
body += f'<div class="custom-control"><input type="checkbox" class="custom-control-input" id="{c.id}" name="option"'

View File

@ -406,7 +406,6 @@ class Submission(Base):
self.views += amount*random.randint(3, 5)
self.upvotes += amount
g.db.add(self)
g.db.commit()
if show_polls:
for c in self.options:

View File

@ -218,7 +218,6 @@ class User(Base):
if not self.has_badge(134):
new_badge = Badge(badge_id=134, user_id=self.id)
g.db.add(new_badge)
g.db.commit()
return True
return False

View File

@ -75,7 +75,6 @@ def award_timers(v, bot=False):
if dirty:
g.db.add(v)
g.db.commit()
def award_timers_bots_task():
accs = g.db.query(User).filter(User.id.in_(bots))

View File

@ -21,6 +21,7 @@ def cron(every_5m, every_1h, every_1d, every_1mo):
if every_5m:
lottery.check_if_end_lottery_task()
offsitementions.offsite_mentions_task()
g.db.commit()
if every_1h:
pass
@ -30,6 +31,8 @@ def cron(every_5m, every_1h, every_1d, every_1mo):
route_static.stats_cached()
awards.award_timers_bots_task()
sub_inactive_purge_task()
g.db.commit()
if every_1mo:
give_monthly_marseybux_task()
give_monthly_marseybux_task()
g.db.commit()

View File

@ -58,7 +58,6 @@ def end_lottery_session():
active_lottery.is_active = False
g.db.commit()
return True, f'{winning_user.username} won {active_lottery.prize} coins!'
@ -75,7 +74,6 @@ def start_new_lottery_session():
lottery.is_active = True
g.db.add(lottery)
g.db.commit()
def check_if_end_lottery_task():
@ -110,7 +108,6 @@ def purchase_lottery_tickets(v, quantity=1):
most_recent_lottery.prize += net_ticket_value
most_recent_lottery.tickets_sold += quantity
g.db.commit()
if quantity == 1: return True, f'Successfully purchased {quantity} lottery ticket!'
return True, f'Successfully purchased {quantity} lottery tickets!'
@ -126,4 +123,3 @@ def grant_lottery_tickets_to_user(v, quantity):
active_lottery.prize += prize_value
active_lottery.tickets_sold += quantity
g.db.commit()

View File

@ -84,5 +84,4 @@ def notify_mentions(send_to, mentions, mention_str='site mention'):
notif = Notification(comment_id=new_comment.id, user_id=user_id)
g.db.add(notif)
g.db.commit()

View File

@ -59,7 +59,6 @@ def get_logged_in_user():
if (v.last_active + LOGGEDIN_ACTIVE_TIME) < timestamp:
v.last_active = timestamp
g.db.add(v)
g.db.commit()
else:
ua = str(user_agents.parse(g.agent))
if not ua.startswith('Spider') and 'bot' not in ua.lower():
@ -79,7 +78,6 @@ def check_ban_evade(v):
if v and not v.patron and v.admin_level < 2 and v.ban_evade and not v.unban_utc:
v.shadowbanned = "AutoJanny"
g.db.add(v)
g.db.commit()
def auth_desired(f):
def wrapper(*args, **kwargs):

View File

@ -84,6 +84,5 @@ def activate(v):
badge_grant(user=user, badge_id=2)
g.db.add(user)
g.db.commit()
return render_template("message_success.html", v=v, title="Email verified.", message=f"Your email {email} has been verified. Thank you.")

View File

@ -46,7 +46,6 @@ def give_monthly_marseybux_task():
)
g.db.add(ma)
g.db.commit()
return True
@ -57,7 +56,6 @@ def kippy(v):
kippy = get_account(KIPPY_ID)
kippy.procoins += 10000
g.db.add(kippy)
g.db.commit()
return '10k marseycoins printed!'
@app.get('/admin/loggedin')
@ -127,7 +125,6 @@ def merge(v, id1, id2):
g.db.add(user1)
g.db.add(user2)
g.db.commit()
cache.clear()
return redirect(user1.url)
@ -174,7 +171,6 @@ def merge_all(v, id):
g.db.add(alt)
g.db.add(user)
g.db.commit()
cache.clear()
return redirect(user.url)
@ -210,7 +206,6 @@ if SITE_NAME == 'PCM':
)
g.db.add(ma)
g.db.commit()
return render_template('admin/sidebar.html', v=v, sidebar=sidebar, msg='Sidebar edited successfully!')
@ -232,7 +227,6 @@ def make_admin(v, username):
)
g.db.add(ma)
g.db.commit()
return {"message": "User has been made admin!"}
@ -251,7 +245,6 @@ def remove_admin(v, username):
)
g.db.add(ma)
g.db.commit()
return {"message": "Admin removed!"}
@app.post("/distribute/<comment>")
@ -299,7 +292,6 @@ def distribute(v, comment):
)
g.db.add(ma)
g.db.commit()
return {"message": f"Each winner has received {coinsperperson} coins!"}
@app.post("/@<username>/revert_actions")
@ -347,7 +339,6 @@ def revert_actions(v, username):
send_repeatable_notification(u.id, f"@{v.username} has unbanned you!")
g.db.add(u)
g.db.commit()
return {"message": "Admin actions reverted!"}
@app.post("/@<username>/club_allow")
@ -375,7 +366,6 @@ def club_allow(v, username):
)
g.db.add(ma)
g.db.commit()
return {"message": f"@{username} has been allowed into the {CC_TITLE}!"}
@app.post("/@<username>/club_ban")
@ -402,7 +392,6 @@ def club_ban(v, username):
)
g.db.add(ma)
g.db.commit()
return {"message": f"@{username} has been kicked from the {CC_TITLE}. Deserved."}
@ -527,7 +516,6 @@ def change_settings(v, setting):
)
g.db.add(ma)
g.db.commit()
return {'message': f"{setting} {word}d successfully!"}
@ -559,7 +547,6 @@ def under_attack(v):
user_id=v.id,
)
g.db.add(ma)
g.db.commit()
response = str(requests.patch(f'https://api.cloudflare.com/client/v4/zones/{CF_ZONE}/settings/security_level', headers=CF_HEADERS, data='{"value":"medium"}', timeout=5))
if response == "<Response [200]>": return {"message": "Under attack mode disabled!"}
@ -570,7 +557,6 @@ def under_attack(v):
user_id=v.id,
)
g.db.add(ma)
g.db.commit()
response = str(requests.patch(f'https://api.cloudflare.com/client/v4/zones/{CF_ZONE}/settings/security_level', headers=CF_HEADERS, data='{"value":"under_attack"}', timeout=5))
if response == "<Response [200]>": return {"message": "Under attack mode enabled!"}
@ -627,7 +613,6 @@ def badge_grant_post(v):
)
g.db.add(ma)
g.db.commit()
return render_template("admin/badge_grant.html", v=v, badge_types=badges, msg="Badge granted!")
@ -667,7 +652,6 @@ def badge_remove_post(v):
g.db.delete(badge)
g.db.commit()
return render_template("admin/badge_remove.html", v=v, badge_types=badges, msg="Badge removed!")
@ -845,7 +829,6 @@ def admin_link_accounts(v):
)
g.db.add(ma)
g.db.commit()
return redirect(f"/admin/alt_votes?u1={get_account(u1).username}&u2={get_account(u2).username}")
@ -930,7 +913,6 @@ def agendaposter(user_id, v):
send_repeatable_notification(user.id, f"@{v.username} has marked you as a chud ({note}).")
g.db.commit()
return redirect(user.url)
@ -961,7 +943,6 @@ def unagendaposter(user_id, v):
send_repeatable_notification(user.id, f"@{v.username} has unmarked you as a chud.")
g.db.commit()
return {"message": "Chud theme disabled!"}
@ -988,7 +969,6 @@ def shadowban(user_id, v):
cache.delete_memoized(frontlist)
notify_mod_action(v.id, f"@{v.username} has shadowbanned @{user.username}")
g.db.commit()
return {"message": "User shadowbanned!"}
@ -1015,7 +995,6 @@ def unshadowban(user_id, v):
cache.delete_memoized(frontlist)
notify_mod_action(v.id, f"@{v.username} has unshadowbanned @{user.username}")
g.db.commit()
return {"message": "User unshadowbanned!"}
@ -1054,7 +1033,6 @@ def admin_title_change(user_id, v):
_note=f'"{user.customtitleplain}"'
)
g.db.add(ma)
g.db.commit()
return redirect(user.url)
@ -1121,7 +1099,6 @@ def ban_user(user_id, v):
g.db.add(comment)
notify_mod_action(v.id, f"@{v.username} has banned @{user.username} ({note})")
g.db.commit()
if 'redir' in request.values: return redirect(user.url)
else: return {"message": f"@{user.username} was banned!"}
@ -1159,7 +1136,6 @@ def unban_user(user_id, v):
g.db.add(ma)
notify_mod_action(v.id, f"@{v.username} has unbanned @{user.username}")
g.db.commit()
if "@" in request.referrer: return redirect(user.url)
else: return {"message": f"@{user.username} was unbanned!"}
@ -1201,7 +1177,6 @@ def ban_post(post_id, v):
requests.post(f'https://api.cloudflare.com/client/v4/zones/{CF_ZONE}/purge_cache',
headers=CF_HEADERS, json={'files': [f"{SITE_FULL}/logged_out/"]}, timeout=5)
g.db.commit()
return {"message": "Post removed!"}
@ -1241,7 +1216,6 @@ def unban_post(post_id, v):
if v.id != post.author_id:
notify_mod_action(v.id, f"@{v.username} has approved [{post.title}]({post.shortlink}) by @{post.author.username}")
g.db.commit()
return {"message": "Post approved!"}
@ -1272,7 +1246,6 @@ def api_distinguish_post(post_id, v):
)
g.db.add(ma)
g.db.commit()
if post.distinguish_level: return {"message": "Post distinguished!"}
else: return {"message": "Post undistinguished!"}
@ -1304,7 +1277,6 @@ def sticky_post(post_id, v):
send_repeatable_notification(post.author_id, f"@{v.username} has pinned your [post](/post/{post_id})!")
cache.delete_memoized(frontlist)
g.db.commit()
return {"message": "Post pinned!"}
@app.post("/unsticky/<post_id>")
@ -1330,7 +1302,6 @@ def unsticky_post(post_id, v):
send_repeatable_notification(post.author_id, f"@{v.username} has unpinned your [post](/post/{post_id})!")
cache.delete_memoized(frontlist)
g.db.commit()
return {"message": "Post unpinned!"}
@app.post("/sticky_comment/<cid>")
@ -1354,7 +1325,6 @@ def sticky_comment(cid, v):
message = f"@{v.username} has pinned your [comment]({comment.shortlink})!"
send_repeatable_notification(comment.author_id, message)
g.db.commit()
return {"message": "Comment pinned!"}
@ -1381,7 +1351,6 @@ def unsticky_comment(cid, v):
message = f"@{v.username} has unpinned your [comment]({comment.shortlink})!"
send_repeatable_notification(comment.author_id, message)
g.db.commit()
return {"message": "Comment unpinned!"}
@ -1408,7 +1377,6 @@ def api_ban_comment(c_id, v):
if v.id != comment.author_id:
notify_mod_action(v.id, f"@{v.username} has removed [comment]({comment.shortlink}) by @{comment.author.username}")
g.db.commit()
return {"message": "Comment removed!"}
@ -1440,7 +1408,6 @@ def api_unban_comment(c_id, v):
if v.id != comment.author_id:
notify_mod_action(v.id, f"@{v.username} has approved [comment]({comment.shortlink}) by @{comment.author.username}")
g.db.commit()
return {"message": "Comment approved!"}
@ -1470,7 +1437,6 @@ def admin_distinguish_comment(c_id, v):
)
g.db.add(ma)
g.db.commit()
if comment.distinguish_level: return {"message": "Comment distinguished!"}
else: return {"message": "Comment undistinguished!"}
@ -1526,7 +1492,6 @@ def admin_toggle_ban_domain(v):
)
g.db.add(ma)
g.db.commit()
return redirect("/admin/banned_domains/")
@ -1563,7 +1528,6 @@ def admin_nuke_user(v):
notify_mod_action(v.id, f"@{v.username} has nuked @{user.username}")
g.db.commit()
return redirect(user.url)
@ -1600,6 +1564,5 @@ def admin_nunuke_user(v):
notify_mod_action(v.id, f"@{v.username} has un-nuked @{user.username}")
g.db.commit()
return redirect(user.url)

View File

@ -97,7 +97,6 @@ def buy(v, award):
if CARP_ID and v.id != CARP_ID and og_price >= 10000:
send_repeatable_notification(CARP_ID, f"@{v.username} has bought a `{award}` award!")
g.db.commit()
return {"message": "Award bought!"}
@ -298,7 +297,6 @@ def award_thing(v, thing_type, id):
else: author.received_award_count = 1
g.db.add(author)
g.db.commit()
if request.referrer and len(request.referrer) > 1:
if request.referrer == f'{SITE_FULL}/submit': return redirect(thing.permalink)
elif request.referrer.startswith(f'{SITE_FULL}/'): return redirect(request.referrer)
@ -371,7 +369,6 @@ def admin_userawards_post(v):
)
g.db.add(ma)
g.db.commit()
if v.admin_level != 3: return render_template("admin/awards.html", awards=list(AWARDS3.values()), v=v)
return render_template("admin/awards.html", awards=list(AWARDS.values()), v=v)

View File

@ -66,7 +66,6 @@ def speak(data, v):
emit('speak', data)
v.shadowbanned = 'AutoJanny'
g.db.add(v)
g.db.commit()
else:
emit('speak', data, broadcast=True)
messages.append(data)

View File

@ -83,7 +83,6 @@ def post_pid_comment_cid(cid, pid=None, anything=None, v=None, sub=None):
if notif:
notif.read = True
g.db.add(notif)
g.db.commit()
if comment.post and comment.post.club and not (v and (v.paid_dues or v.id in [comment.author_id, comment.post.author_id])): abort(403)
@ -644,7 +643,6 @@ def api_comment(v):
parent_post.comment_count += 1
g.db.add(parent_post)
g.db.commit()
if request.headers.get("Authorization"): return c.json
return {"comment": render_template("comments.html", v=v, comments=[c], ajax=True)}
@ -806,7 +804,6 @@ def edit_comment(cid, v):
n = Notification(comment_id=c.id, user_id=x)
g.db.add(n)
g.db.commit()
return {"comment": c.realbody(v)}
@ -829,7 +826,6 @@ def delete_comment(cid, v):
cache.delete_memoized(comment_idlist)
g.db.commit()
return {"message": "Comment deleted!"}
@ -850,7 +846,6 @@ def undelete_comment(cid, v):
cache.delete_memoized(comment_idlist)
g.db.commit()
return {"message": "Comment undeleted!"}
@ -874,7 +869,6 @@ def pin_comment(cid, v):
else: message = f"@{v.username} (OP) has pinned your [comment]({comment.shortlink})!"
send_repeatable_notification(comment.author_id, message)
g.db.commit()
return {"message": "Comment pinned!"}
@ -896,7 +890,6 @@ def unpin_comment(cid, v):
if v.id != comment.author_id:
message = f"@{v.username} (OP) has unpinned your [comment]({comment.shortlink})!"
send_repeatable_notification(comment.author_id, message)
g.db.commit()
return {"message": "Comment unpinned!"}
@ -917,7 +910,6 @@ def mod_pin(cid, v):
message = f"@{v.username} (Mod) has pinned your [comment]({comment.shortlink})!"
send_repeatable_notification(comment.author_id, message)
g.db.commit()
return {"message": "Comment pinned!"}
@ -936,7 +928,6 @@ def mod_unpin(cid, v):
if v.id != comment.author_id:
message = f"@{v.username} (Mod) has unpinned your [comment]({comment.shortlink})!"
send_repeatable_notification(comment.author_id, message)
g.db.commit()
return {"message": "Comment unpinned!"}
@ -954,7 +945,6 @@ def save_comment(cid, v):
new_save=CommentSaveRelationship(user_id=v.id, comment_id=comment.id)
g.db.add(new_save)
g.db.commit()
return {"message": "Comment saved!"}
@ -970,7 +960,6 @@ def unsave_comment(cid, v):
if save:
g.db.delete(save)
g.db.commit()
return {"message": "Comment unsaved!"}
@ -991,7 +980,6 @@ def handle_blackjack_action(cid, v):
g.db.add(comment)
g.db.add(v)
g.db.commit()
return {"response" : comment.blackjack_html(v)}
@ -1042,6 +1030,5 @@ def handle_wordle_action(cid, v):
comment.wordle_result = f'{guesses}_{status}_{answer}'
g.db.add(comment)
g.db.commit()
return {"response" : comment.wordle_html(v)}

View File

@ -140,6 +140,5 @@ def discord_redirect(v):
requests.patch(url, headers=headers, json=data, timeout=5)
g.db.commit()
return redirect(f"https://discord.com/channels/{SERVER_ID}/{WELCOME_CHANNEL}")

View File

@ -14,7 +14,6 @@ def clear(v):
for n in notifs:
n.read = True
g.db.add(n)
g.db.commit()
return {"message": "Notifications cleared!"}
@app.get("/unread")
@ -31,7 +30,6 @@ def unread(v):
for n, c in listing:
n.read = True
g.db.add(n)
g.db.commit()
return {"data":[x[1].json for x in listing]}
@ -162,7 +160,6 @@ def notifications(v):
if c not in listing: listing.append(c)
g.db.commit()
if request.headers.get("Authorization"): return {"data":[x.json for x in listing]}
@ -334,7 +331,6 @@ def frontlist(v=None, sort="hot", page=1, t="all", ids_only=True, ccmode="false"
if ids_only: posts = [x.id for x in posts]
g.db.commit()
return posts, next_exists

View File

@ -148,7 +148,6 @@ def login_post():
check_for_alts(account.id)
g.db.commit()
redir = request.values.get("redirect")
if redir:
@ -353,7 +352,6 @@ def sign_up_post(v):
if existing_account:
return signup_error("An account with that username already exists.")
g.db.commit()
check_for_alts(new_user.id)
@ -361,7 +359,6 @@ def sign_up_post(v):
session["lo_user"] = new_user.id
g.db.commit()
return redirect(SITE_FULL)
@ -479,7 +476,6 @@ def post_reset(v):
user.passhash = hash_password(password)
g.db.add(user)
g.db.commit()
return render_template("message_success.html",
title="Password reset successful!",
@ -558,7 +554,6 @@ def reset_2fa():
g.db.add(user)
g.db.commit()
return render_template("message_success.html",
title="Two-factor authentication removed.",

View File

@ -30,7 +30,6 @@ def authorize(v):
try:
new_auth = ClientAuth(oauth_client = application.id, user_id = v.id, access_token=access_token)
g.db.add(new_auth)
g.db.commit()
except sqlalchemy.exc.IntegrityError:
g.db.rollback()
old_auth = g.db.query(ClientAuth).filter_by(oauth_client = application.id, user_id = v.id).one()
@ -76,7 +75,6 @@ def request_api_keys(v):
g.db.add(notif)
g.db.commit()
return redirect('/settings/apps')
@ -97,7 +95,6 @@ def delete_oauth_app(v, aid):
g.db.delete(app)
g.db.commit()
return redirect('/apps')
@ -119,7 +116,6 @@ def edit_oauth_app(v, aid):
g.db.add(app)
g.db.commit()
return redirect('/settings/apps')
@ -153,7 +149,6 @@ def admin_app_approve(v, aid):
)
g.db.add(ma)
g.db.commit()
return {"message": "Application approved"}
@ -178,7 +173,6 @@ def admin_app_revoke(v, aid):
)
g.db.add(ma)
g.db.commit()
return {"message": "App revoked"}
@ -204,7 +198,6 @@ def admin_app_reject(v, aid):
)
g.db.add(ma)
g.db.commit()
return {"message": "App rejected"}
@ -281,6 +274,5 @@ def reroll_oauth_tokens(aid, v):
a.client_id = secrets.token_urlsafe(64)[:64]
g.db.add(a)
g.db.commit()
return {"message": "Client ID Rerolled", "id": a.client_id}

View File

@ -51,7 +51,6 @@ def toggle_club(pid, v):
post.club = not post.club
g.db.add(post)
g.db.commit()
if post.club: return {"message": "Post has been marked as club-only!"}
else: return {"message": "Post has been unmarked as club-only!"}
@ -91,7 +90,6 @@ def publish(pid, v):
if post.sub:
on_post_hole_entered(post)
g.db.commit()
cache.delete_memoized(frontlist)
cache.delete_memoized(User.userpagelisting)
@ -241,7 +239,6 @@ def post_id(pid, anything=None, v=None, sub=None):
post.views += 1
g.db.add(post)
g.db.commit()
if request.headers.get("Authorization"): return post.json
else:
if post.is_banned and not (v and (v.admin_level > 1 or post.author_id == v.id)): template = "submission_banned.html"
@ -521,7 +518,6 @@ def edit_post(pid, v):
)
g.db.add(ma)
g.db.commit()
return redirect(p.permalink)
@ -1214,7 +1210,6 @@ def submit_post(v, sub=None):
post.upvotes += 3
g.db.add(post)
g.db.commit()
cache.delete_memoized(frontlist)
cache.delete_memoized(User.userpagelisting)
@ -1250,7 +1245,6 @@ def delete_post_pid(pid, v):
cache.delete_memoized(frontlist)
cache.delete_memoized(User.userpagelisting)
g.db.commit()
return {"message": "Post deleted!"}
@ -1267,7 +1261,6 @@ def undelete_post_pid(pid, v):
cache.delete_memoized(frontlist)
cache.delete_memoized(User.userpagelisting)
g.db.commit()
return {"message": "Post undeleted!"}
@ -1290,7 +1283,6 @@ def toggle_comment_nsfw(cid, v):
target_comment_id = comment.id,
)
g.db.add(ma)
g.db.commit()
if comment.over_18: return {"message": "Comment has been marked as +18!"}
else: return {"message": "Comment has been unmarked as +18!"}
@ -1313,7 +1305,6 @@ def toggle_post_nsfw(pid, v):
target_submission_id = post.id,
)
g.db.add(ma)
g.db.commit()
if post.over_18: return {"message": "Post has been marked as +18!"}
else: return {"message": "Post has been unmarked as +18!"}
@ -1331,7 +1322,6 @@ def save_post(pid, v):
if not save:
new_save=SaveRelationship(user_id=v.id, submission_id=post.id)
g.db.add(new_save)
g.db.commit()
return {"message": "Post saved!"}
@ -1347,7 +1337,6 @@ def unsave_post(pid, v):
if save:
g.db.delete(save)
g.db.commit()
return {"message": "Post unsaved!"}
@ -1363,7 +1352,6 @@ def api_pin_post(post_id, v):
cache.delete_memoized(User.userpagelisting)
g.db.commit()
if post.is_pinned: return {"message": "Post pinned!"}
else: return {"message": "Post unpinned!"}
return {"error": "Post not found!"}

View File

@ -46,7 +46,6 @@ def api_flag_post(pid, v):
flag = Flag(post_id=post.id, user_id=v.id, reason=reason)
g.db.add(flag)
g.db.commit()
return {"message": "Post reported!"}
@ -77,7 +76,6 @@ def api_flag_comment(cid, v):
flag = CommentFlag(comment_id=comment.id, user_id=v.id, reason=reason)
g.db.add(flag)
g.db.commit()
return {"message": "Comment reported!"}
@ -105,7 +103,6 @@ def remove_report_post(v, pid, uid):
g.db.add(ma)
g.db.commit()
return {"message": "Report removed successfully!"}
@ -131,6 +128,5 @@ def remove_report_comment(v, cid, uid):
g.db.add(ma)
g.db.commit()
return {"message": "Report removed successfully!"}

View File

@ -38,7 +38,6 @@ tiers={
def removebackground(v):
v.background = None
g.db.add(v)
g.db.commit()
return {"message": "Background removed!"}
@app.post("/settings/profile")
@ -118,28 +117,24 @@ def settings_profile_post(v):
v.bio = None
v.bio_html = None
g.db.add(v)
g.db.commit()
return render_template("settings_profile.html", v=v, msg="Your bio has been updated.")
elif request.values.get("sig") == "":
v.sig = None
v.sig_html = None
g.db.add(v)
g.db.commit()
return render_template("settings_profile.html", v=v, msg="Your sig has been updated.")
elif request.values.get("friends") == "":
v.friends = None
v.friends_html = None
g.db.add(v)
g.db.commit()
return render_template("settings_profile.html", v=v, msg="Your friends list has been updated.")
elif request.values.get("enemies") == "":
v.enemies = None
v.enemies_html = None
g.db.add(v)
g.db.commit()
return render_template("settings_profile.html", v=v, msg="Your enemies list has been updated.")
elif (v.patron or v.id == MOOSE_ID) and request.values.get("sig"):
@ -155,7 +150,6 @@ def settings_profile_post(v):
v.sig = sig[:200]
v.sig_html=sig_html
g.db.add(v)
g.db.commit()
return render_template("settings_profile.html",
v=v,
msg="Your sig has been updated.")
@ -184,7 +178,6 @@ def settings_profile_post(v):
v.friends = friends[:500]
v.friends_html=friends_html
g.db.add(v)
g.db.commit()
return render_template("settings_profile.html",
v=v,
msg="Your friends list has been updated.")
@ -211,7 +204,6 @@ def settings_profile_post(v):
v.enemies = enemies[:500]
v.enemies_html=enemies_html
g.db.add(v)
g.db.commit()
return render_template("settings_profile.html",
v=v,
msg="Your enemies list has been updated.")
@ -236,7 +228,6 @@ def settings_profile_post(v):
v.bio = bio[:1500]
v.bio_html=bio_html
g.db.add(v)
g.db.commit()
return render_template("settings_profile.html",
v=v,
msg="Your bio has been updated.")
@ -300,7 +291,6 @@ def settings_profile_post(v):
if updated:
g.db.add(v)
g.db.commit()
return {"message": "Your settings have been updated."}
@ -318,7 +308,6 @@ def filters(v):
v.custom_filter_list=filters
g.db.add(v)
g.db.commit()
return render_template("settings_filters.html", v=v, msg="Your custom filters have been updated.")
@app.post("/changelogsub")
@ -329,7 +318,6 @@ def changelogsub(v):
cache.delete_memoized(frontlist)
g.db.commit()
if v.changelogsub: return {"message": "You have subscribed to the changelog!"}
else: return {"message": "You have unsubscribed from the changelog!"}
@ -347,7 +335,6 @@ def namecolor(v):
v.namecolor = color
g.db.add(v)
g.db.commit()
return redirect("/settings/profile")
@app.post("/settings/themecolor")
@ -364,7 +351,6 @@ def themecolor(v):
v.themecolor = themecolor
g.db.add(v)
g.db.commit()
return redirect("/settings/profile")
@app.post("/settings/gumroad")
@ -401,7 +387,6 @@ def gumroad(v):
badge_grant(badge_id=20+tier, user=v)
g.db.commit()
return {"message": f"{patron} rewards claimed!"}
@ -418,7 +403,6 @@ def titlecolor(v):
return render_template("settings_profile.html", v=v, error="Invalid color code")
v.titlecolor = titlecolor
g.db.add(v)
g.db.commit()
return redirect("/settings/profile")
@app.post("/settings/verifiedcolor")
@ -431,7 +415,6 @@ def verifiedcolor(v):
if len(verifiedcolor) != 6: return render_template("settings_profile.html", v=v, error="Invalid color code")
v.verifiedcolor = verifiedcolor
g.db.add(v)
g.db.commit()
return redirect("/settings/profile")
@app.post("/settings/security")
@ -453,7 +436,6 @@ def settings_security_post(v):
g.db.add(v)
g.db.commit()
return render_template("settings_security.html", v=v, msg="Your password has been changed.")
@ -497,7 +479,6 @@ def settings_security_post(v):
v.mfa_secret = secret
g.db.add(v)
g.db.commit()
return render_template("settings_security.html", v=v, msg="Two-factor authentication enabled.")
@ -514,7 +495,6 @@ def settings_security_post(v):
v.mfa_secret = None
g.db.add(v)
g.db.commit()
return render_template("settings_security.html", v=v, msg="Two-factor authentication disabled.")
@ -535,7 +515,6 @@ def settings_log_out_others(v):
g.db.add(v)
g.db.commit()
return render_template("settings_security.html", v=v, msg="All other devices have been logged out")
@ -571,7 +550,6 @@ def settings_images_profile(v):
v.profileurl = imageurl
g.db.add(v)
g.db.commit()
return render_template("settings_profile.html", v=v, msg="Profile picture successfully updated.")
@ -595,7 +573,6 @@ def settings_images_banner(v):
if path.isfile(fpath): os.remove(fpath)
v.bannerurl = bannerurl
g.db.add(v)
g.db.commit()
return render_template("settings_profile.html", v=v, msg="Banner successfully updated.")
@ -622,7 +599,6 @@ def settings_css(v):
css = request.values.get("css").strip().replace('\\', '').strip()[:4000]
v.css = css
g.db.add(v)
g.db.commit()
return render_template("settings_css.html", v=v)
@ -649,7 +625,6 @@ def settings_profilecss(v):
v.profilecss = profilecss
g.db.add(v)
g.db.commit()
return render_template("settings_profilecss.html", v=v)
@app.post("/settings/block")
@ -665,7 +640,6 @@ def settings_block_user(v):
if user.unblockable:
if not v.shadowbanned:
send_notification(user.id, f"@{v.username} has tried to block you and failed because of your unblockable status!")
g.db.commit()
return {"error": "This user is unblockable."}, 403
if user.id == v.id:
@ -686,7 +660,6 @@ def settings_block_user(v):
cache.delete_memoized(frontlist)
g.db.commit()
return {"message": f"@{user.username} blocked."}
@ -710,7 +683,6 @@ def settings_unblock_user(v):
cache.delete_memoized(frontlist)
g.db.commit()
return {"message": f"@{user.username} unblocked."}
@ -733,7 +705,6 @@ def settings_remove_discord(v):
v.discord_id=None
g.db.add(v)
g.db.commit()
return redirect("/settings/profile")
@ -784,7 +755,6 @@ def settings_name_change(v):
g.db.add(v)
g.db.commit()
return redirect("/settings/profile")
@ -810,7 +780,6 @@ def settings_song_change_mp3(v):
v.song = v.id
g.db.add(v)
g.db.commit()
return redirect("/settings/profile")
@ -828,7 +797,6 @@ def settings_song_change(v):
os.remove(f"/songs/{v.song}.mp3")
v.song = None
g.db.add(v)
g.db.commit()
return redirect("/settings/profile")
song = song.replace("https://music.youtube.com", "https://youtube.com")
@ -845,7 +813,6 @@ def settings_song_change(v):
if path.isfile(f'/songs/{id}.mp3'):
v.song = id
g.db.add(v)
g.db.commit()
return redirect("/settings/profile")
@ -892,7 +859,6 @@ def settings_song_change(v):
v.song = id
g.db.add(v)
g.db.commit()
return redirect("/settings/profile")
@ -914,7 +880,6 @@ def settings_title_change(v):
if len(v.customtitle) < 1000:
g.db.add(v)
g.db.commit()
return redirect("/settings/profile")
@ -935,7 +900,6 @@ def settings_checkmark_text(v):
v.verified = new_name
g.db.add(v)
g.db.commit()
return redirect("/settings/profile")

View File

@ -219,7 +219,6 @@ def submit_contact(v):
g.db.commit()
return render_template("contact.html", v=v, msg="Your message has been sent.")
@app.get('/archives')

View File

@ -29,7 +29,6 @@ def exile_post(v, pid):
send_notification(u.id, f"@{v.username} has exiled you from /h/{sub} for [{p.title}]({p.shortlink})")
g.db.commit()
return {"message": "User exiled successfully!"}
@ -57,7 +56,6 @@ def exile_comment(v, cid):
send_notification(u.id, f"@{v.username} has exiled you from /h/{sub} for [{c.permalink}]({c.shortlink})")
g.db.commit()
return {"message": "User exiled successfully!"}
@ -75,7 +73,6 @@ def unexile(v, sub, uid):
send_notification(u.id, f"@{v.username} has revoked your exile from /h/{sub}")
g.db.commit()
if request.headers.get("Authorization") or request.headers.get("xhr"): return {"message": "User unexiled successfully!"}
@ -101,7 +98,6 @@ def block_sub(v, sub):
if not existing:
block = SubBlock(user_id=v.id, sub=sub)
g.db.add(block)
g.db.commit()
cache.delete_memoized(frontlist)
return {"message": "Sub blocked successfully!"}
@ -118,7 +114,6 @@ def unblock_sub(v, sub):
if block:
g.db.delete(block)
g.db.commit()
cache.delete_memoized(frontlist)
return {"message": "Sub unblocked successfully!"}
@ -134,7 +129,6 @@ def follow_sub(v, sub):
if not existing:
subscription = SubSubscription(user_id=v.id, sub=sub.name)
g.db.add(subscription)
g.db.commit()
return {"message": "Sub followed successfully!"}
@ -148,7 +142,6 @@ def unfollow_sub(v, sub):
.filter_by(user_id=v.id, sub=sub.name).one_or_none()
if subscription:
g.db.delete(subscription)
g.db.commit()
return {"message": "Sub unfollowed successfully!"}
@ -225,7 +218,6 @@ def add_mod(v, sub):
if v.id != user.id:
send_repeatable_notification(user.id, f"@{v.username} has added you as a mod to /h/{sub}")
g.db.commit()
return redirect(f'/h/{sub}/mods')
@ -260,7 +252,6 @@ def remove_mod(v, sub):
if v.id != user.id:
send_repeatable_notification(user.id, f"@{v.username} has removed you as a mod from /h/{sub}")
g.db.commit()
return redirect(f'/h/{sub}/mods')
@ -299,7 +290,6 @@ def create_sub2(v):
g.db.flush()
mod = Mod(user_id=v.id, sub=sub.name)
g.db.add(mod)
g.db.commit()
return redirect(f'/h/{sub.name}')
@ -316,7 +306,6 @@ def kick(v, pid):
post.sub = None
g.db.add(post)
g.db.commit()
cache.delete_memoized(frontlist)
@ -351,7 +340,6 @@ def rehole_post(v, pid, hole):
g.db.add(ma)
on_post_hole_entered(post)
g.db.commit()
return {"message": f"Post moved to {sub_to_str}!"}
@ -397,7 +385,6 @@ def post_sub_sidebar(v, sub):
g.db.add(sub)
g.db.commit()
return redirect(f'/h/{sub.name}/settings')
@ -426,7 +413,6 @@ def post_sub_css(v, sub):
sub.css = css
g.db.add(sub)
g.db.commit()
return redirect(f'/h/{sub.name}/settings')
@ -464,7 +450,6 @@ def sub_banner(v, sub):
if path.isfile(fpath): os.remove(fpath)
sub.bannerurl = bannerurl
g.db.add(sub)
g.db.commit()
return redirect(f'/h/{sub.name}/settings')
@ -491,7 +476,6 @@ def sub_sidebar(v, sub):
if path.isfile(fpath): os.remove(fpath)
sub.sidebarurl = sidebarurl
g.db.add(sub)
g.db.commit()
return redirect(f'/h/{sub.name}/settings')
@ -538,5 +522,4 @@ def sub_inactive_purge_task():
for x in dead_holes:
g.db.delete(x)
g.db.commit()
return True

View File

@ -401,7 +401,6 @@ def suicide(v, username):
suicide = f"Hi there,\n\nA [concerned user](/id/{v.id}) reached out to us about you.\n\nWhen you're in the middle of something painful, it may feel like you don't have a lot of options. But whatever you're going through, you deserve help and there are people who are here for you.\n\nThere are resources available in your area that are free, confidential, and available 24/7:\n\n- Call, Text, or Chat with Canada's [Crisis Services Canada](https://www.crisisservicescanada.ca/en/)\n- Call, Email, or Visit the UK's [Samaritans](https://www.samaritans.org/)\n- Text CHAT to America's [Crisis Text Line](https://www.crisistextline.org/) at 741741.\nIf you don't see a resource in your area above, the moderators keep a comprehensive list of resources and hotlines for people organized by location. Find Someone Now\n\nIf you think you may be depressed or struggling in another way, don't ignore it or brush it aside. Take yourself and your feelings seriously, and reach out to someone.\n\nIt may not feel like it, but you have options. There are people available to listen to you, and ways to move forward.\n\nYour fellow users care about you and there are people who want to help."
if not v.shadowbanned:
send_notification(user.id, suicide)
g.db.commit()
return {"message": "Help message sent!"}
@ -451,7 +450,6 @@ def transfer_coins(v, username):
g.db.add(receiver)
g.db.add(v)
g.db.commit()
return {"message": f"{amount-tax} coins transferred!"}, 200
@ -491,7 +489,6 @@ def transfer_bux(v, username):
g.db.add(receiver)
g.db.add(v)
g.db.commit()
return {"message": f"{amount} marseybux transferred!"}, 200
return {"message": "You can't transfer marseybux to yourself!"}, 400
@ -636,7 +633,6 @@ def song(song):
def subscribe(v, post_id):
new_sub = Subscription(user_id=v.id, submission_id=post_id)
g.db.add(new_sub)
g.db.commit()
return {"message": "Post subscribed!"}
@app.post("/unsubscribe/<post_id>")
@ -647,7 +643,6 @@ def unsubscribe(v, post_id):
sub=g.db.query(Subscription).filter_by(user_id=v.id, submission_id=post_id).one_or_none()
if sub:
g.db.delete(sub)
g.db.commit()
return {"message": "Post unsubscribed!"}
@app.get("/report_bugs")
@ -709,7 +704,6 @@ def message2(v, username):
notif = Notification(comment_id=c.id, user_id=user.id)
g.db.add(notif)
g.db.commit()
if PUSHER_ID != 'blahblahblah' and not v.shadowbanned:
if len(message) > 500: notifbody = message[:500] + '...'
@ -817,7 +811,6 @@ def messagereply(v):
for n in notifications:
g.db.delete(n)
g.db.commit()
return {"comment": render_template("comments.html", v=v, comments=[c], ajax=True)}
@ -930,7 +923,6 @@ def u_username(username, v=None):
else: view = ViewerRelationship(viewer_id=v.id, user_id=u.id)
g.db.add(view)
g.db.commit()
if u.is_private and (not v or (v.id != u.id and v.admin_level < 2 and not v.eye)):
@ -1122,7 +1114,6 @@ def follow_user(username, v):
if not v.shadowbanned:
send_notification(target.id, f"@{v.username} has followed you!")
g.db.commit()
return {"message": "User followed!"}
@ -1137,7 +1128,6 @@ def unfollow_user(username, v):
if target.fish:
if not v.shadowbanned:
send_notification(target.id, f"@{v.username} has tried to unfollow you and failed because of your fish award!")
g.db.commit()
return {"error": "You can't unfollow this user!"}
follow = g.db.query(Follow).filter_by(user_id=v.id, target_id=target.id).one_or_none()
@ -1152,7 +1142,6 @@ def unfollow_user(username, v):
if not v.shadowbanned:
send_notification(target.id, f"@{v.username} has unfollowed you!")
g.db.commit()
return {"message": "User unfollowed!"}
@ -1175,7 +1164,6 @@ def remove_follow(username, v):
send_repeatable_notification(target.id, f"@{v.username} has removed your follow!")
g.db.commit()
return {"message": "Follower removed!"}
@ -1272,5 +1260,4 @@ def fp(v, fp):
g.db.flush()
print(v.username + ' + ' + u.username, flush=True)
g.db.add(v)
g.db.commit()
return '', 204

View File

@ -117,7 +117,6 @@ def api_vote_post(post_id, new, v):
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()
return "", 204
@app.post("/vote/comment/<comment_id>/<new>")
@ -194,7 +193,6 @@ def api_vote_comment(comment_id, new, v):
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()
return "", 204
@ -226,7 +224,6 @@ def api_vote_poll(comment_id, v):
g.db.flush()
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
@ -258,7 +255,6 @@ def bet(comment_id, v):
autobetter.coins += 200
g.db.add(autobetter)
g.db.commit()
return "", 204
@app.post("/vote/choice/<comment_id>")
@ -290,5 +286,4 @@ def api_vote_choice(comment_id, v):
g.db.flush()
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