Revert "restore autoflush"

This reverts commit 687cd766b9.
remotes/1693045480750635534/spooky-22
Aevann1 2022-08-23 17:17:37 +02:00
parent 1b07392cd5
commit 5aa03d87bb
8 changed files with 26 additions and 4 deletions

View File

@ -72,7 +72,7 @@ Base = declarative_base()
engine = create_engine(app.config['SQLALCHEMY_DATABASE_URL'])
db_session = scoped_session(sessionmaker(bind=engine))
db_session = scoped_session(sessionmaker(bind=engine, autoflush=False))
cache = Cache(app)
Compress(app)

View File

@ -48,7 +48,17 @@ def notif_comment(text):
text_html = sanitize(text)
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()
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()
if existing: return existing[0]
else: return create_comment(text_html)

View File

@ -77,6 +77,7 @@ 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)

View File

@ -77,14 +77,17 @@ 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)
@ -129,6 +132,7 @@ 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'):

View File

@ -82,6 +82,7 @@ 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)

View File

@ -258,9 +258,10 @@ def comment(v):
all_by_author = g.db.query(Marsey).filter_by(author_id=user.id).count()
if all_by_author >= 100:
# off-by-one: newly added marsey isn't counted
if all_by_author >= 99:
badge_grant(badge_id=143, user=user)
elif all_by_author >= 10:
elif all_by_author >= 9:
badge_grant(badge_id=16, user=user)
else:
badge_grant(badge_id=17, user=user)

View File

@ -1314,6 +1314,7 @@ 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

View File

@ -79,6 +79,7 @@ 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:
@ -120,6 +121,7 @@ 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()
@ -152,6 +154,7 @@ 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:
@ -194,6 +197,7 @@ 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()