diff --git a/files/routes/comments.py b/files/routes/comments.py index 69e42b98d0..b32f7b0349 100644 --- a/files/routes/comments.py +++ b/files/routes/comments.py @@ -387,6 +387,9 @@ def comment(v:User): g.db.flush() + if c.parent_submission: + cache.delete(f'post_{c.parent_submission}') + if v.client: return c.json(db=g.db) return {"comment": render_template("comments.html", v=v, comments=[c])} diff --git a/files/routes/posts.py b/files/routes/posts.py index c7e4a4261c..7df8949bd9 100644 --- a/files/routes/posts.py +++ b/files/routes/posts.py @@ -95,6 +95,10 @@ def post_id(pid, anything=None, v=None, sub=None): if g.is_api_or_xhr: abort(451, "Must be 18+ to view") return render_template("errors/nsfw.html", v=v) + if not v and not request.values.get("sort"): + result = cache.get(f'post_{p.id}') + if result: return result + if p.new: defaultsortingcomments = 'new' elif v: defaultsortingcomments = v.defaultsortingcomments else: defaultsortingcomments = "hot" @@ -173,10 +177,15 @@ def post_id(pid, anything=None, v=None, sub=None): and not (v and (v.admin_level >= PERMS['POST_COMMENT_MODERATION'] or p.author_id == v.id)): template = "submission_banned.html" - return render_template(template, v=v, p=p, ids=list(ids), + result = render_template(template, v=v, p=p, ids=list(ids), sort=sort, render_replies=True, offset=offset, sub=p.subr, fart=get_setting('fart_mode')) + if not v and not request.values.get("sort"): + cache.set(f'post_{p.id}', result) + + return result + @app.get("/view_more///") @limiter.limit(DEFAULT_RATELIMIT) @auth_desired_with_logingate