restore autoflush

pull/142/head
Aevann 2023-03-16 06:21:57 +02:00
parent 132f7a4115
commit a392fbb86d
7 changed files with 2 additions and 16 deletions

View File

@ -549,7 +549,6 @@ class User(Base):
@lazy
def has_badge(self, badge_id):
db.flush()
return db.query(Badge).filter_by(user_id=self.id, badge_id=badge_id).one_or_none()
def verifyPass(self, password):

View File

@ -8,7 +8,7 @@ import tldextract
import datetime
engine = create_engine(environ.get("DATABASE_URL").strip())
db_session = scoped_session(sessionmaker(bind=engine, autoflush=False))
db_session = scoped_session(sessionmaker(bind=engine))
db = db_session()
t = datetime.datetime.now()

View File

@ -83,7 +83,6 @@ def submit_marsey(v:User):
marsey = Marsey(name=name, author_id=author.id, tags=tags, count=0, submitter_id=v.id)
db.add(marsey)
db.flush()
if v.admin_level >= PERMS['VIEW_PENDING_SUBMITTED_MARSEYS']: marseys = db.query(Marsey).filter(Marsey.submitter_id != None)
else: marseys = db.query(Marsey).filter(Marsey.submitter_id == v.id)

View File

@ -400,7 +400,6 @@ def delete_comment(cid, v):
db.add(c)
cache.delete_memoized(comment_idlist)
db.flush()
v.comment_count = db.query(Comment).filter(
Comment.author_id == v.id,
or_(Comment.parent_submission != None, Comment.wall_user_id != None),
@ -421,7 +420,7 @@ def undelete_comment(cid, v):
c.deleted_utc = 0
db.add(c)
cache.delete_memoized(comment_idlist)
db.flush()
v.comment_count = db.query(Comment).filter(
Comment.author_id == v.id,
or_(Comment.parent_submission != None, Comment.wall_user_id != None),

View File

@ -734,7 +734,6 @@ def delete_post_pid(pid, v):
cache.delete_memoized(frontlist)
cache.delete_memoized(userpagelisting)
db.flush()
v.post_count = db.query(Submission).filter_by(author_id=v.id, deleted_utc=0).count()
db.add(v)
@ -756,7 +755,6 @@ def undelete_post_pid(pid, v):
cache.delete_memoized(frontlist)
cache.delete_memoized(userpagelisting)
db.flush()
v.post_count = db.query(Submission).filter_by(author_id=v.id, deleted_utc=0).count()
db.add(v)

View File

@ -812,7 +812,6 @@ def u_username_wall(v:Optional[User], username:str):
is_following = v and u.has_follower(v)
if v and v.id != u.id and not v.admin_level:
db.flush()
view = db.query(ViewerRelationship).filter_by(viewer_id=v.id, user_id=u.id).one_or_none()
if view: view.last_view_utc = int(time.time())
else: view = ViewerRelationship(viewer_id=v.id, user_id=u.id)
@ -867,7 +866,6 @@ def u_username_wall_comment(v:User, username:str, cid):
is_following = v and u.has_follower(v)
if v and v.id != u.id and not v.admin_level:
db.flush()
view = db.query(ViewerRelationship).filter_by(viewer_id=v.id, user_id=u.id).one_or_none()
if view: view.last_view_utc = int(time.time())
else: view = ViewerRelationship(viewer_id=v.id, user_id=u.id)
@ -921,7 +919,6 @@ def u_username(v:Optional[User], username:str):
return render_template("userpage/private.html", u=u, v=v, is_following=is_following), 403
if v and v.id != u.id and not v.admin_level:
db.flush()
view = db.query(ViewerRelationship).filter_by(viewer_id=v.id, user_id=u.id).one_or_none()
if view: view.last_view_utc = int(time.time())
else: view = ViewerRelationship(viewer_id=v.id, user_id=u.id)
@ -998,7 +995,6 @@ def u_username_comments(username, v=None):
return render_template("userpage/private.html", u=u, v=v, is_following=is_following), 403
if v and v.id != u.id and not v.admin_level:
db.flush()
view = db.query(ViewerRelationship).filter_by(viewer_id=v.id, user_id=u.id).one_or_none()
if view: view.last_view_utc = int(time.time())
else: view = ViewerRelationship(viewer_id=v.id, user_id=u.id)
@ -1093,7 +1089,6 @@ def follow_user(username, v):
new_follow = Follow(user_id=v.id, target_id=target.id)
db.add(new_follow)
db.flush()
target.stored_subscriber_count = db.query(Follow).filter_by(target_id=target.id).count()
db.add(target)
@ -1122,7 +1117,6 @@ def unfollow_user(username, v):
if follow:
db.delete(follow)
db.flush()
target.stored_subscriber_count = db.query(Follow).filter_by(target_id=target.id).count()
db.add(target)
@ -1149,7 +1143,6 @@ def remove_follow(username, v):
db.delete(follow)
db.flush()
v.stored_subscriber_count = db.query(Follow).filter_by(target_id=v.id).count()
db.add(v)
@ -1328,7 +1321,6 @@ tiers={
marseybux_li = (0,2500,5000,10000,25000,50000,100000,250000)
def claim_rewards(v):
db.flush()
transactions = db.query(Transaction).filter_by(email=v.email, claimed=None).all()
highest_tier = 0

View File

@ -76,7 +76,6 @@ def vote_post_comment(target_id, new, v, cls, vote_cls):
coin_mult = 1
db.flush()
existing = db.query(vote_cls).filter_by(user_id=v.id)
if vote_cls == Vote:
existing = existing.filter_by(submission_id=target.id)