From 687cd766b9ffb1b44c6f4f265a3c50bb5c699974 Mon Sep 17 00:00:00 2001 From: Aevann1 Date: Wed, 17 Aug 2022 18:36:59 +0200 Subject: [PATCH] restore autoflush --- files/__main__.py | 2 +- files/helpers/actions.py | 1 - files/helpers/alerts.py | 12 +----------- files/helpers/cron.py | 1 - files/routes/admin.py | 5 ----- files/routes/awards.py | 1 - files/routes/comments.py | 5 ++--- files/routes/subs.py | 1 - files/routes/users.py | 1 - files/routes/votes.py | 4 ---- 10 files changed, 4 insertions(+), 29 deletions(-) diff --git a/files/__main__.py b/files/__main__.py index 9b3832f92..79d2e7b21 100644 --- a/files/__main__.py +++ b/files/__main__.py @@ -72,7 +72,7 @@ Base = declarative_base() engine = create_engine(app.config['SQLALCHEMY_DATABASE_URL']) -db_session = scoped_session(sessionmaker(bind=engine, autoflush=False)) +db_session = scoped_session(sessionmaker(bind=engine)) cache = Cache(app) Compress(app) diff --git a/files/helpers/actions.py b/files/helpers/actions.py index 832f7900f..62cce7eed 100644 --- a/files/helpers/actions.py +++ b/files/helpers/actions.py @@ -21,7 +21,6 @@ def badge_grant(user, badge_id, description=None, url=None): ) g.db.add(badge) - g.db.flush() send_repeatable_notification(user.id, f"@AutoJanny has given you the following profile badge:\n\n" + diff --git a/files/helpers/alerts.py b/files/helpers/alerts.py index 17484885a..ec973f118 100644 --- a/files/helpers/alerts.py +++ b/files/helpers/alerts.py @@ -48,17 +48,7 @@ def notif_comment(text): text_html = sanitize(text) - try: existing = g.db.query(Comment.id).filter_by(author_id=AUTOJANNY_ID, parent_submission=None, body_html=text_html, is_bot=True).one_or_none() - except: - existing = g.db.query(Comment).filter_by(author_id=AUTOJANNY_ID, parent_submission=None, body_html=text_html, is_bot=True).all() - - notifs = g.db.query(Notification).filter(Notification.comment_id.in_([x.id for x in existing])).all() - for c in notifs: g.db.delete(c) - g.db.flush() - - for c in existing: g.db.delete(c) - g.db.flush() - existing = g.db.query(Comment.id).filter_by(author_id=AUTOJANNY_ID, parent_submission=None, body_html=text_html, is_bot=True).one_or_none() + existing = g.db.query(Comment.id).filter_by(author_id=AUTOJANNY_ID, parent_submission=None, body_html=text_html, is_bot=True).one_or_none() if existing: return existing[0] else: return create_comment(text_html) diff --git a/files/helpers/cron.py b/files/helpers/cron.py index 1f893a71a..9c1ecc2d5 100644 --- a/files/helpers/cron.py +++ b/files/helpers/cron.py @@ -77,7 +77,6 @@ def sub_inactive_purge_task(): for x in to_delete: g.db.delete(x) - g.db.flush() for x in dead_holes: g.db.delete(x) diff --git a/files/routes/admin.py b/files/routes/admin.py index 39e43ea4c..e7f178e67 100644 --- a/files/routes/admin.py +++ b/files/routes/admin.py @@ -77,17 +77,14 @@ def merge(v, id1, id2): if not user1.has_badge(badge.badge_id): badge.user_id = user1.id g.db.add(badge) - g.db.flush() for mod in mods: if not user1.mods(mod.sub): mod.user_id = user1.id g.db.add(mod) - g.db.flush() for exile in exiles: if not user1.exiled_from(exile.sub): exile.user_id = user1.id g.db.add(exile) - g.db.flush() for kind in ('comment_count', 'post_count', 'winnings', 'received_award_count', 'coins_spent', 'lootboxes_bought', 'coins', 'truecoins', 'procoins'): amount = getattr(user1, kind) + getattr(user2, kind) @@ -132,7 +129,6 @@ def merge_all(v, id): if not user.has_badge(badge.badge_id): badge.user_id = user.id g.db.add(badge) - g.db.flush() for alt in user.alts_unique: for kind in ('comment_count', 'post_count', 'winnings', 'received_award_count', 'coins_spent', 'lootboxes_bought', 'coins', 'truecoins', 'procoins'): @@ -548,7 +544,6 @@ def badge_grant_post(v): if url: new_badge.url = url g.db.add(new_badge) - g.db.flush() if v.id != user.id: text = f"@{v.username} has given you the following profile badge:\n\n![]({new_badge.path})\n\n{new_badge.name}" diff --git a/files/routes/awards.py b/files/routes/awards.py index 80c58bdd9..2c48c1b83 100644 --- a/files/routes/awards.py +++ b/files/routes/awards.py @@ -82,7 +82,6 @@ def buy(v, award): lootbox_items.append(AWARDS[award]['title']) award = AwardRelationship(user_id=v.id, kind=award) g.db.add(award) - g.db.flush() v.lootboxes_bought += 1 lootbox_msg = "You open your lootbox and receive: " + ', '.join(lootbox_items) diff --git a/files/routes/comments.py b/files/routes/comments.py index 81b348121..e97e33313 100644 --- a/files/routes/comments.py +++ b/files/routes/comments.py @@ -253,10 +253,9 @@ def comment(v): all_by_author = g.db.query(Marsey).filter_by(author_id=user.id).count() - # off-by-one: newly added marsey isn't counted - if all_by_author >= 99: + if all_by_author >= 100: badge_grant(badge_id=143, user=user) - elif all_by_author >= 9: + elif all_by_author >= 10: badge_grant(badge_id=16, user=user) else: badge_grant(badge_id=17, user=user) diff --git a/files/routes/subs.py b/files/routes/subs.py index 80cc29326..b7f659efc 100644 --- a/files/routes/subs.py +++ b/files/routes/subs.py @@ -291,7 +291,6 @@ def create_sub2(v): sub = Sub(name=name) g.db.add(sub) - g.db.flush() mod = Mod(user_id=v.id, sub=sub.name) g.db.add(mod) diff --git a/files/routes/users.py b/files/routes/users.py index f75bf6479..dea2693d9 100644 --- a/files/routes/users.py +++ b/files/routes/users.py @@ -1308,7 +1308,6 @@ def fp(v, fp): if existing: continue new_alt = Alt(user1=v.id, user2=u.id) g.db.add(new_alt) - g.db.flush() print(v.username + ' + ' + u.username, flush=True) g.db.add(v) return '', 204 diff --git a/files/routes/votes.py b/files/routes/votes.py index 1d53751c2..0fce7adba 100644 --- a/files/routes/votes.py +++ b/files/routes/votes.py @@ -79,7 +79,6 @@ def vote_post(post_id, new, v): coin_mult = 1 - g.db.flush() existing = g.db.query(Vote).filter_by(user_id=v.id, submission_id=post.id).one_or_none() if DOUBLE_XP_ENABLED > 0: @@ -121,7 +120,6 @@ def vote_post(post_id, new, v): ) g.db.add(vote) - g.db.flush() 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() @@ -154,7 +152,6 @@ def vote_comment(comment_id, new, v): coin_mult = 1 - g.db.flush() existing = g.db.query(CommentVote).filter_by(user_id=v.id, comment_id=comment.id).one_or_none() if DOUBLE_XP_ENABLED > 0: @@ -197,7 +194,6 @@ def vote_comment(comment_id, new, v): g.db.add(vote) - g.db.flush() 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()