From bfde0d7ff3324fa588bcaaa1b96f4356739d3065 Mon Sep 17 00:00:00 2001 From: Aevann Date: Sun, 7 May 2023 21:47:17 +0300 Subject: [PATCH] Revert "paginate /marseys" This reverts commit b53b0e6ac7f66c121c46ace04a43ea7f1cbf183f. --- files/routes/asset_submissions.py | 4 +++ files/routes/static.py | 41 ++++++++++++------------------- files/templates/marseys.html | 21 +++++++--------- 3 files changed, 29 insertions(+), 37 deletions(-) diff --git a/files/routes/asset_submissions.py b/files/routes/asset_submissions.py index 7a3a0fa6f..75fa831cc 100644 --- a/files/routes/asset_submissions.py +++ b/files/routes/asset_submissions.py @@ -183,6 +183,8 @@ def approve_emoji(v, name): cache.delete("emojis") + if emoji.kind == "Marsey": + cache.delete("marseys") purge_files_in_cache(f"https://{SITE}/e/{emoji.name}/webp") @@ -491,6 +493,8 @@ def update_emoji(v): g.db.add(ma) cache.delete("emojis") + if existing.kind == "Marsey": + cache.delete("marseys") return render_template("admin/update_assets.html", v=v, msg=f"'{name}' updated successfully!", name=name, tags=tags, kind=kind, type="Emoji") diff --git a/files/routes/static.py b/files/routes/static.py index b8b505634..6f1185f08 100644 --- a/files/routes/static.py +++ b/files/routes/static.py @@ -2,7 +2,6 @@ import os from shutil import copyfile from sqlalchemy import func -from sqlalchemy.sql.expression import nullslast from files.helpers.media import * import files.helpers.stats as statshelper @@ -42,44 +41,36 @@ def reddit_post(subreddit, v, path): return redirect(f'https://{reddit}/{post_id}') +@cache.cached(key_prefix="marseys") +def get_marseys(db:scoped_session): + if not FEATURES['MARSEYS']: return [] + marseys = [] + for marsey, author in db.query(Emoji, User).join(User, Emoji.author_id == User.id).filter(Emoji.kind == "Marsey", Emoji.submitter_id == None).order_by(Emoji.count.desc()): + marsey.author = author.username if FEATURES['ASSET_SUBMISSIONS'] else None + marseys.append(marsey) + return marseys + @app.get("/marseys") @app.get("/marseys/all") @limiter.limit(DEFAULT_RATELIMIT) @limiter.limit(DEFAULT_RATELIMIT, key_func=get_ID) @auth_required def marseys(v:User): - if SITE_NAME != 'rDrama' or not FEATURES['MARSEYS']: + + if SITE_NAME != 'rDrama': abort(404) - marseys = g.db.query(Emoji, User).join(User, Emoji.author_id == User.id).filter(Emoji.kind == "Marsey", Emoji.submitter_id==None) - - total = marseys.count() - - sort = request.values.get("sort", "usage") - if sort == "author": - marseys = marseys.order_by(User.username, Emoji.count.desc()) - elif sort == "name": - marseys = marseys.order_by(Emoji.name, Emoji.count.desc()) - elif sort == "added_on": - marseys = marseys.order_by(nullslast(Emoji.created_utc.desc()), Emoji.count.desc()) - elif sort == "usage": - marseys = marseys.order_by(Emoji.count.desc(), User.username) - - page = get_page() - - if request.path != "/marseys/all": - marseys = marseys.offset(PAGE_SIZE*(page-1)).limit(PAGE_SIZE) - - marseys = marseys.all() - + marseys = get_marseys(g.db) + authors = get_accounts_dict([m.author_id for m in marseys], v=v, graceful=True) original = os.listdir("/asset_submissions/emojis/original") - for marsey, user in marseys: + for marsey in marseys: + marsey.user = authors.get(marsey.author_id) for x in IMAGE_FORMATS: if f'{marsey.name}.{x}' in original: marsey.og = f'{marsey.name}.{x}' break + return render_template("marseys.html", v=v, marseys=marseys) - return render_template("marseys.html", v=v, marseys=marseys, page=page, total=total, sort=sort) @cache.cached(key_prefix="emojis") diff --git a/files/templates/marseys.html b/files/templates/marseys.html index 4e6e04ee6..0a9de3e19 100644 --- a/files/templates/marseys.html +++ b/files/templates/marseys.html @@ -5,25 +5,28 @@
- - - + + + + {% if FEATURES['ASSET_SUBMISSIONS'] %} - + {% endif %} - + {% if FEATURES['ASSET_SUBMISSIONS'] %} {% endif %} -{% for marsey, user in marseys %} +{% for marsey in marseys %} + {% if FEATURES['ASSET_SUBMISSIONS'] %} + {% set user = marsey.user %} {% endif %} @@ -40,9 +43,3 @@
NameMarseyUsage#NameMarseyUsageAuthorAuthorAdded onAdded onOriginal File
{{loop.index}} {{marsey.name}} :#{{marsey.name}}: {{marsey.count}}{% include "user_in_table.html" %}
{% endblock %} - -{% block pagenav %} -{% if request.path != "/marseys/all" %} - {% include "pagination.html" %} -{% endif %} -{% endblock %}