fix /emojis getting cached on browser end

pull/142/head
Aevann 2023-03-19 17:15:20 +02:00
parent d66e404e00
commit 2a9dfab16a
4 changed files with 17 additions and 7 deletions

View File

@ -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);

View File

@ -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

View File

@ -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")

View File

@ -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