cache posts in redis

pull/143/head
Aevann 2023-05-03 17:40:36 +03:00
parent 2c0023436f
commit 6c397ea291
2 changed files with 13 additions and 1 deletions

View File

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

View File

@ -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/<int:pid>/<sort>/<offset>")
@limiter.limit(DEFAULT_RATELIMIT)
@auth_desired_with_logingate