restore autoflush

master
Aevann1 2022-08-17 18:36:59 +02:00
parent 6765655eb9
commit 687cd766b9
10 changed files with 4 additions and 29 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, autoflush=False))
db_session = scoped_session(sessionmaker(bind=engine))
cache = Cache(app)
Compress(app)

View File

@ -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" +

View File

@ -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)

View File

@ -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)

View File

@ -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}"

View File

@ -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)

View File

@ -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)

View File

@ -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)

View File

@ -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

View File

@ -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()