more quert optimization

master
Aevann1 2022-07-03 13:21:58 +02:00
parent b1bfa255bb
commit 72884713ac
2 changed files with 6 additions and 3 deletions

View File

@ -113,7 +113,7 @@ def get_account(id, v=None):
return user
def get_post(i, v=None, graceful=False, rendered=False):
def get_post(i, v=None, graceful=False, rendered=False, entered=False):
try: i = int(i)
except: abort(404)
@ -144,13 +144,16 @@ def get_post(i, v=None, graceful=False, rendered=False):
)
if rendered:
posts = post.options(
post = post.options(
joinedload(Submission.flags),
joinedload(Submission.awards),
joinedload(Submission.author),
joinedload(Submission.options).joinedload(SubmissionOption.votes)
)
if entered:
post = post.options(joinedload(Submission.comments))
post=post.one_or_none()
if not post:

View File

@ -128,7 +128,7 @@ def post_id(pid, anything=None, v=None, sub=None):
try: pid = int(pid)
except: abort(404)
post = get_post(pid, v=v, rendered=True)
post = get_post(pid, v=v, rendered=True, entered=True)
if post.over_18 and not (v and v.over_18) and session.get('over_18', 0) < int(time.time()):
if request.headers.get("Authorization") or request.headers.get("xhr"): return {"error":"Must be 18+ to view"}, 451