diff --git a/files/routes/asset_submissions.py b/files/routes/asset_submissions.py index e8489deaf..c8696b643 100644 --- a/files/routes/asset_submissions.py +++ b/files/routes/asset_submissions.py @@ -240,13 +240,16 @@ def approve_emoji(v, name): if emoji.nsfw: OVER_18_EMOJIS.append(emoji.name) + g.db.commit() + cache.delete("emojis_True") cache.delete(f"emoji_list_{emoji.kind}_True") if not emoji.nsfw: cache.delete("emojis_False") cache.delete(f"emoji_list_{emoji.kind}_False") - cache.set("emojis_num", g.db.query(Emoji).filter_by(submitter_id=None).count()) + + cache.delete("emoji_count") purge_files_in_cloudflare_cache(f"{SITE_FULL_IMAGES}/e/{emoji.name}/webp") @@ -565,6 +568,8 @@ def update_emoji(v): ) g.db.add(ma) + g.db.commit() + cache.delete("emojis_True") cache.delete(f"emoji_list_{existing.kind}_True") if not existing.nsfw: diff --git a/files/routes/jinja2.py b/files/routes/jinja2.py index 3ec10ae64..54879b943 100644 --- a/files/routes/jinja2.py +++ b/files/routes/jinja2.py @@ -11,6 +11,7 @@ from sqlalchemy import text from files.classes.user import User from files.classes.orgy import get_running_orgy +from files.classes.emoji import Emoji from files.helpers.assetcache import assetcache_path from files.helpers.config.const import * from files.helpers.const_stateful import OVER_18_EMOJIS @@ -122,6 +123,10 @@ def bar_position(): return [int((vaxxed * 100) / total), int((zombie * 100) / total), vaxxed, zombie] +@cache.cached(make_cache_key=lambda:"emoji_count") +def emoji_count(): + return g.db.query(Emoji).filter_by(submitter_id=None).count() + @app.context_processor def inject_constants(): return {"environ":environ, "SITE":SITE, "SITE_NAME":SITE_NAME, "SITE_FULL":SITE_FULL, @@ -151,5 +156,5 @@ def inject_constants(): "CHUD_PHRASES":CHUD_PHRASES, "hasattr":hasattr, "calc_users":calc_users, "HOLE_INACTIVITY_DELETION":HOLE_INACTIVITY_DELETION, "LIGHT_THEMES":LIGHT_THEMES, "OVER_18_EMOJIS":OVER_18_EMOJIS, "MAX_IMAGE_AUDIO_SIZE_MB":MAX_IMAGE_AUDIO_SIZE_MB, "MAX_IMAGE_AUDIO_SIZE_MB_PATRON":MAX_IMAGE_AUDIO_SIZE_MB_PATRON, "MAX_VIDEO_SIZE_MB":MAX_VIDEO_SIZE_MB, "MAX_VIDEO_SIZE_MB_PATRON":MAX_VIDEO_SIZE_MB_PATRON, - "CURSORMARSEY_DEFAULT":CURSORMARSEY_DEFAULT, "SNAPPY_ID":SNAPPY_ID, "get_running_orgy":get_running_orgy, "TRUESCORE_MINIMUM":TRUESCORE_MINIMUM, "bar_position":bar_position, "datetime":datetime, "CSS_LENGTH_LIMIT":CSS_LENGTH_LIMIT, "cache":cache, + "CURSORMARSEY_DEFAULT":CURSORMARSEY_DEFAULT, "SNAPPY_ID":SNAPPY_ID, "get_running_orgy":get_running_orgy, "TRUESCORE_MINIMUM":TRUESCORE_MINIMUM, "bar_position":bar_position, "datetime":datetime, "CSS_LENGTH_LIMIT":CSS_LENGTH_LIMIT, "cache":cache, "emoji_count":emoji_count, } diff --git a/files/templates/modals/emoji.html b/files/templates/modals/emoji.html index 78fe931af..c158819b9 100644 --- a/files/templates/modals/emoji.html +++ b/files/templates/modals/emoji.html @@ -70,8 +70,7 @@ -{% set emoji_num = cache.get("emojis_num") or 0 %} - +