From 5056f09380b363cdd82177dd657e7df4e7db81dd Mon Sep 17 00:00:00 2001 From: justcool393 Date: Tue, 29 Nov 2022 15:49:06 -0600 Subject: [PATCH] chat: fix 500 on some... weird... state... i think? cache: get out of jinja templates chat: threshold is now a const --- files/helpers/const.py | 5 +++-- files/routes/admin.py | 12 ++++++------ files/routes/chat.py | 6 +++--- files/routes/jinja2.py | 2 +- files/routes/wrappers.py | 2 ++ files/templates/header.html | 2 +- files/templates/mobile_navigation_bar.html | 5 ++--- 7 files changed, 18 insertions(+), 16 deletions(-) diff --git a/files/helpers/const.py b/files/helpers/const.py index 26901ec51..419f9a688 100644 --- a/files/helpers/const.py +++ b/files/helpers/const.py @@ -62,6 +62,7 @@ IS_LOCALHOST = SITE == "localhost" or SITE == "127.0.0.1" or SITE.startswith("19 if IS_LOCALHOST: SITE_FULL = 'http://' + SITE else: SITE_FULL = 'https://' + SITE +CHAT_ONLINE_CACHE_KEY = f'{SITE}_online' REDDIT_NOTIFS_CACHE_KEY = "reddit_notifications" MARSEYS_CACHE_KEY = "marseys" EMOJIS_CACHE_KEY = "emojis" @@ -397,6 +398,7 @@ COSMETIC_AWARD_COIN_AWARD_PCT = 0.10 TRUESCORE_CHAT_MINIMUM = 0 TRUESCORE_DONATE_MINIMUM = 100 TRUESCORE_GHOST_MINIMUM = 0 +CHAT_DISPLAY_USER_COUNT_MINIMUM = 0 LOGGEDIN_ACTIVE_TIME = 15 * 60 PFP_DEFAULT_MARSEY = True @@ -507,6 +509,7 @@ if SITE == 'rdrama.net': CHAT_LENGTH_LIMIT = 200 TRUESCORE_CHAT_MINIMUM = 10 TRUESCORE_GHOST_MINIMUM = 10 + CHAT_DISPLAY_USER_COUNT_MINIMUM = 10 NEW_USER_HAT_AGE = 7 * 86400 HOLE_COST = 50000 @@ -1633,8 +1636,6 @@ tiers={ has_sidebar = path.exists(f'files/templates/sidebar_{SITE_NAME}.html') has_logo = path.exists(f'files/assets/images/{SITE_NAME}/logo.webp') -ONLINE_STR = f'{SITE}_online' - forced_hats = { "rehab": ("Roulette", "I'm a recovering ludomaniac!"), "progressivestack": ("Attention Whore", "I won the oppression olympics!"), diff --git a/files/routes/admin.py b/files/routes/admin.py index 00d228f4b..cdddee1d4 100644 --- a/files/routes/admin.py +++ b/files/routes/admin.py @@ -96,9 +96,9 @@ def merge(v, id1, id2): g.db.add(user1) g.db.add(user2) - online = cache.get(ONLINE_STR) + online = cache.get(CHAT_ONLINE_CACHE_KEY) cache.clear() - cache.set(ONLINE_STR, online) + cache.set(CHAT_ONLINE_CACHE_KEY, online) return redirect(user1.url) @@ -146,9 +146,9 @@ def merge_all(v, id): g.db.add(user) - online = cache.get(ONLINE_STR) + online = cache.get(CHAT_ONLINE_CACHE_KEY) cache.clear() - cache.set(ONLINE_STR, online) + cache.set(CHAT_ONLINE_CACHE_KEY, online) return redirect(user.url) @@ -480,9 +480,9 @@ def clear_cloudflare_cache(v): @app.post("/admin/clear_internal_cache") @admin_level_required(PERMS['SITE_CACHE_DUMP_INTERNAL']) def admin_clear_internal_cache(v): - online = cache.get(ONLINE_STR) + online = cache.get(CHAT_ONLINE_CACHE_KEY) cache.clear() - cache.set(ONLINE_STR, online) + cache.set(CHAT_ONLINE_CACHE_KEY, online) ma = ModAction( kind="clear_internal_cache", user_id=v.id diff --git a/files/routes/chat.py b/files/routes/chat.py index 0a0cc3fdc..62158e1d9 100644 --- a/files/routes/chat.py +++ b/files/routes/chat.py @@ -29,7 +29,7 @@ else: typing = [] online = [] -cache.set(ONLINE_STR, len(online), timeout=0) +cache.set(CHAT_ONLINE_CACHE_KEY, len(online), timeout=0) muted = cache.get(f'{SITE}_muted') or {} messages = cache.get(f'{SITE}_chat') or [] total = cache.get(f'{SITE}_total') or 0 @@ -113,7 +113,7 @@ def connect(v): if v.username not in online: online.append(v.username) emit("online", online, broadcast=True) - cache.set(ONLINE_STR, len(online), timeout=0) + cache.set(CHAT_ONLINE_CACHE_KEY, len(online), timeout=0) if not socket_ids_to_user_ids.get(request.sid): socket_ids_to_user_ids[request.sid] = v.id @@ -130,7 +130,7 @@ def disconnect(v): if v.username in online: online.remove(v.username) emit("online", online, broadcast=True) - cache.set(ONLINE_STR, len(online), timeout=0) + cache.set(CHAT_ONLINE_CACHE_KEY, len(online), timeout=0) if v.username in typing: typing.remove(v.username) diff --git a/files/routes/jinja2.py b/files/routes/jinja2.py index 09b3b66a1..848436453 100644 --- a/files/routes/jinja2.py +++ b/files/routes/jinja2.py @@ -51,7 +51,7 @@ def inject_constants(): "HOLE_NAME":HOLE_NAME, "HOLE_STYLE_FLAIR":HOLE_STYLE_FLAIR, "HOLE_REQUIRED":HOLE_REQUIRED, "GUMROAD_LINK":GUMROAD_LINK, "DEFAULT_THEME":DEFAULT_THEME, "DESCRIPTION":DESCRIPTION, "has_sidebar":has_sidebar, "has_logo":has_logo, - "FP":FP, "cache":cache, "ONLINE_STR":ONLINE_STR, "patron":patron, "DUES":DUES, + "FP":FP, "CHAT_DISPLAY_USER_COUNT_MINIMUM":CHAT_DISPLAY_USER_COUNT_MINIMUM, "patron":patron, "DUES":DUES, "SIDEBAR_THREAD":SIDEBAR_THREAD, "BANNER_THREAD":BANNER_THREAD, "BADGE_THREAD":BADGE_THREAD, "SNAPPY_THREAD":SNAPPY_THREAD, "KOFI_TOKEN":KOFI_TOKEN, "KOFI_LINK":KOFI_LINK, diff --git a/files/routes/wrappers.py b/files/routes/wrappers.py index f1c6e4471..27b79436b 100644 --- a/files/routes/wrappers.py +++ b/files/routes/wrappers.py @@ -21,6 +21,7 @@ def calc_users(v): if g.is_api_or_xhr: g.loggedin_counter = 0 g.loggedout_counter = 0 + g.loggedin_chat = 0 return '' loggedin = cache.get(f'{SITE}_loggedin') or {} loggedout = cache.get(f'{SITE}_loggedout') or {} @@ -42,6 +43,7 @@ def calc_users(v): g.loggedin_counter = len(loggedin) g.loggedout_counter = len(loggedout) + g.loggedin_chat = cache.get(CHAT_ONLINE_CACHE_KEY) return '' def get_logged_in_user(): diff --git a/files/templates/header.html b/files/templates/header.html index b75033865..14b5989d3 100644 --- a/files/templates/header.html +++ b/files/templates/header.html @@ -176,7 +176,7 @@ - {{cache.get(ONLINE_STR)}} + {{g.loggedin_chat}} diff --git a/files/templates/mobile_navigation_bar.html b/files/templates/mobile_navigation_bar.html index b32df9faf..141ce3967 100644 --- a/files/templates/mobile_navigation_bar.html +++ b/files/templates/mobile_navigation_bar.html @@ -1,5 +1,4 @@
-
@@ -47,11 +46,11 @@ {% if v %} - {% if FEATURES['CHAT'] and (SITE_NAME != 'rDrama' or cache.get(ONLINE_STR) >= 10) -%} + {% if FEATURES['CHAT'] and g.loggedin_chat >= CHAT_DISPLAY_USER_COUNT_MINIMUM -%}