From f8cfb96a9838e57709d434d94932bac3d16db3ae Mon Sep 17 00:00:00 2001 From: Aevann Date: Tue, 12 Nov 2024 13:09:12 +0200 Subject: [PATCH] extend the fix to other endpoints (might make them faster) --- files/routes/comments.py | 8 +++----- files/routes/posts.py | 14 +++++++------- 2 files changed, 10 insertions(+), 12 deletions(-) diff --git a/files/routes/comments.py b/files/routes/comments.py index e6e68469a..2c6bc2184 100644 --- a/files/routes/comments.py +++ b/files/routes/comments.py @@ -393,14 +393,13 @@ def comment(v): post_target.bump_utc = c.created_utc g.db.add(post_target) - g.db.flush() + g.db.commit() + gevent.spawn(postprocess_comment, c.body, c.body_html, c.id) if c.parent_post: for sort in COMMENT_SORTS.keys(): cache.delete(f'post_{c.parent_post}_{sort}') - gevent.spawn(postprocess_comment, c.body, c.body_html, c.id) - if v.client: return c.json return {"id": c.id, "comment": render_template("comments.html", v=v, comments=[c])} @@ -788,8 +787,7 @@ def edit_comment(cid, v): g.db.add(n) push_notif({x}, f'New mention of you by @{c.author_name}', c.body, c) - g.db.flush() - + g.db.commit() gevent.spawn(postprocess_comment, c.body, c.body_html, c.id) else: stop(400, "You need to change something!") diff --git a/files/routes/posts.py b/files/routes/posts.py index fb409ac6a..0105d07e9 100644 --- a/files/routes/posts.py +++ b/files/routes/posts.py @@ -775,13 +775,6 @@ def submit_post(v, hole=None): ) g.db.add(ma) - cache.delete_memoized(frontlist) - cache.delete_memoized(userpagelisting) - - g.db.flush() #Necessary, do NOT remove - - generate_thumb = (not p.thumburl and p.url and p.domain != SITE) - gevent.spawn(postprocess_post, p.url, p.body, p.body_html, p.id, generate_thumb, False) if not p.draft and flag_effortpost and not (SITE_NAME == 'WPD' and v.truescore < 500) and p.can_be_effortpost: body = f"@{v.username} has requested that {p.textlink} be marked as an effortpost!" @@ -790,6 +783,13 @@ def submit_post(v, hole=None): if p.draft and flag_effortpost and not (SITE_NAME == 'WPD' and v.truescore < 500): p.effortpost = True + g.db.commit() + generate_thumb = (not p.thumburl and p.url and p.domain != SITE) + gevent.spawn(postprocess_post, p.url, p.body, p.body_html, p.id, generate_thumb, False) + + cache.delete_memoized(frontlist) + cache.delete_memoized(userpagelisting) + if v.client: return p.json else: p.voted = 1