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/alerts.py b/files/helpers/alerts.py index 198f02e7c..6e0b81733 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 a5e866f0c..3531e152c 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'): diff --git a/files/routes/awards.py b/files/routes/awards.py index e97c1a443..5e4e3d209 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 5e6b083e8..c79bb4e69 100644 --- a/files/routes/comments.py +++ b/files/routes/comments.py @@ -258,10 +258,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/users.py b/files/routes/users.py index a6a791172..db87f6a10 100644 --- a/files/routes/users.py +++ b/files/routes/users.py @@ -1314,7 +1314,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 77bc3bf7e..65b2fd7cd 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() @@ -159,7 +157,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: @@ -202,7 +199,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()