diff --git a/files/assets/js/emoji_modal.js b/files/assets/js/emoji_modal.js index 8e7649692..23c455dd5 100644 --- a/files/assets/js/emoji_modal.js +++ b/files/assets/js/emoji_modal.js @@ -141,7 +141,7 @@ const emojisSearchDictionary = { // get public emojis list const emojiRequest = new XMLHttpRequest(); -emojiRequest.open("GET", '/emojis.csv'); +emojiRequest.open("GET", '/emojis'); emojiRequest.setRequestHeader('xhr', 'xhr'); emojiRequest.onload = async () => { let emojis = JSON.parse(emojiRequest.response); diff --git a/files/helpers/config/const.py b/files/helpers/config/const.py index 7b3e10ed6..522f38fd8 100644 --- a/files/helpers/config/const.py +++ b/files/helpers/config/const.py @@ -75,6 +75,7 @@ LOGGED_IN_CACHE_KEY = f"{SITE}_loggedin" LOGGED_OUT_CACHE_KEY = f"{SITE}_loggedout" CHAT_ONLINE_CACHE_KEY = f"{SITE}_online" REDDIT_NOTIFS_CACHE_KEY = "reddit_notifications" +EMOJIS_CACHE_KEY = "emojis" MARSEYS_CACHE_KEY = "marseys" SESSION_LIFETIME = 60 * 60 * 24 * 365 diff --git a/files/routes/asset_submissions.py b/files/routes/asset_submissions.py index 8de55027b..1def6f353 100644 --- a/files/routes/asset_submissions.py +++ b/files/routes/asset_submissions.py @@ -180,10 +180,11 @@ def approve_emoji(v, name): badge_grant(badge_id=112, user=author) + cache.delete(EMOJIS_CACHE_KEY) if emoji.kind == "Marsey": cache.delete(MARSEYS_CACHE_KEY) - purge_files_in_cache([f"https://{SITE}/e/{emoji.name}/webp", f"https://{SITE}/emojis.csv"]) + purge_files_in_cache(f"https://{SITE}/e/{emoji.name}/webp") move(f"/asset_submissions/marseys/{name}.webp", f"files/assets/images/emojis/{emoji.name}.webp") diff --git a/files/routes/static.py b/files/routes/static.py index bbc5cd567..4cff7dd99 100644 --- a/files/routes/static.py +++ b/files/routes/static.py @@ -70,17 +70,25 @@ def marseys(v:User): break return render_template("marseys.html", v=v, marseys=marseys) -@app.get("/emojis.csv") -@limiter.limit(DEFAULT_RATELIMIT) -def emoji_list(): - emojis = [] + +@cache.cached(key_prefix=EMOJIS_CACHE_KEY) +def get_emojis(): + emojis = [] for emoji, author in g.db.query(Emoji, User).join(User, Emoji.author_id == User.id).filter(Emoji.submitter_id == None).order_by(Emoji.count.desc()): emoji.author = author.username if FEATURES['ASSET_SUBMISSIONS'] else None emojis.append(emoji.json()) - return emojis +@app.get("/emojis") +@limiter.limit(DEFAULT_RATELIMIT) +@limiter.limit(DEFAULT_RATELIMIT, key_func=get_ID) +@auth_required +def emoji_list(v): + return get_emojis() + + + @app.get('/sidebar') @limiter.limit(DEFAULT_RATELIMIT) @auth_desired