From dfb7f8df71300bbaed475efaa3b666701e41e7b2 Mon Sep 17 00:00:00 2001 From: Aevann1 Date: Thu, 29 Jul 2021 00:38:58 +0200 Subject: [PATCH] fdfdfd --- drama/classes/submission.py | 9 ++++----- drama/routes/front.py | 26 ++++++++++++++++--------- drama/templates/submission_listing.html | 2 +- 3 files changed, 22 insertions(+), 15 deletions(-) diff --git a/drama/classes/submission.py b/drama/classes/submission.py index 6dfe6c6e4..4b3d4b00b 100644 --- a/drama/classes/submission.py +++ b/drama/classes/submission.py @@ -296,10 +296,9 @@ class Submission(Base, Stndrd, Age_times, Scores, Fuzzing): def has_award(self, kind): return bool(len([x for x in self.awards if x.kind == kind])) - def voted(self, v): - vote = v.votes.filter_by(submission_id=self.id).first() - if vote: return vote.vote_type - else: return 0 + @property + def voted(self): + return self._voted if "_voted" in self.__dict__ else 0 @property def title(self): @@ -436,4 +435,4 @@ class SaveRelationship(Base, Stndrd): id=Column(Integer, primary_key=true) user_id=Column(Integer, ForeignKey("users.id")) submission_id=Column(Integer, ForeignKey("submissions.id")) - type=Column(Integer) + type=Column(Integer) \ No newline at end of file diff --git a/drama/routes/front.py b/drama/routes/front.py index 512237cb6..ed264e7ca 100644 --- a/drama/routes/front.py +++ b/drama/routes/front.py @@ -69,8 +69,8 @@ def notifications(v): render_replies=True, is_notification_page=True) - -def frontlist(v=None, sort="hot", page=1,t="all", filter_words='', **kwargs): +@cache.memoize(timeout=1500) +def frontlist(v=None, sort="hot", page=1,t="all", ids_only=True, filter_words='', **kwargs): posts = g.db.query(Submission).options(lazyload('*')).filter_by(is_banned=False,stickied=False,private=False).filter(Submission.deleted_utc == 0) if v and v.admin_level == 0: @@ -169,7 +169,12 @@ def frontlist(v=None, sort="hot", page=1,t="all", filter_words='', **kwargs): post.views = post.views + random.randint(7,10) g.db.add(post) - return [x for x in posts if not (x.author and x.author.shadowbanned) or (v and v.id == x.author_id)][:26] + posts = [x for x in posts if not (x.author and x.author.shadowbanned) or (v and v.id == x.author_id)][:26] + + if ids_only: + posts = [x.id for x in posts] + return posts + return posts @app.get("/") @app.get("/api/v1/listing") @@ -193,7 +198,7 @@ def front_all(v): sort=request.args.get("sort", defaultsorting) t=request.args.get('t', defaulttime) - posts = frontlist(sort=sort, + ids = frontlist(sort=sort, page=page, t=t, v=v, @@ -203,8 +208,11 @@ def front_all(v): ) # check existence of next page - next_exists = (len(posts) == 26) - posts = posts[:25] + next_exists = (len(ids) == 26) + ids = ids[0:25] + + # check if ids exist + posts = get_posts(ids, v=v) if request.path == "/": return render_template("home.html", v=v, listing=posts, next_exists=next_exists, sort=sort, t=t, page=page) else: return jsonify({"data": [x.json for x in posts], "next_exists": next_exists}) @@ -303,7 +311,7 @@ def changelog(v): # check existence of next page next_exists = (len(ids) == 26) - ids = ids[:25] + ids = ids[0:25] # check if ids exist posts = get_posts(ids, v=v) @@ -418,7 +426,7 @@ def all_comments(v): next_exists = len(idlist) == 26 - idlist = idlist[:25] + idlist = idlist[0:25] return {"html": lambda: render_template("home_comments.html", v=v, @@ -428,4 +436,4 @@ def all_comments(v): comments=comments, standalone=True, next_exists=next_exists), - "api": lambda: jsonify({"data": [x.json for x in comments]})} + "api": lambda: jsonify({"data": [x.json for x in comments]})} \ No newline at end of file diff --git a/drama/templates/submission_listing.html b/drama/templates/submission_listing.html index 02359401d..0b6f64566 100644 --- a/drama/templates/submission_listing.html +++ b/drama/templates/submission_listing.html @@ -14,7 +14,7 @@ {% set score=ups-downs %} {% if v %} - {% set voted= p.voted(v) %} + {% set voted= p.voted %} {% else %} {% set voted=-2 %} {% endif %}