From 33c043b42f11eac6679e70142ee46a1ee43e6c1c Mon Sep 17 00:00:00 2001 From: Aevann Date: Wed, 28 Feb 2024 19:16:47 +0200 Subject: [PATCH] change redis default timeout to prevent future confusion (like what happened) --- files/__main__.py | 2 +- files/helpers/cron.py | 2 +- files/routes/chat.py | 8 ++++---- files/routes/front.py | 4 ++-- files/routes/jinja2.py | 2 +- files/routes/login.py | 2 +- files/routes/routehelpers.py | 2 +- files/routes/special.py | 2 +- files/routes/static.py | 4 ++-- files/routes/users.py | 2 +- files/routes/wrappers.py | 4 ++-- 11 files changed, 17 insertions(+), 17 deletions(-) diff --git a/files/__main__.py b/files/__main__.py index 099957a9e..ab8515ea4 100644 --- a/files/__main__.py +++ b/files/__main__.py @@ -50,7 +50,7 @@ app.config['SQLALCHEMY_TRACK_MODIFICATIONS'] = False app.config["CACHE_KEY_PREFIX"] = f"{SITE}_flask_cache_" app.config["CACHE_TYPE"] = "RedisCache" app.config["CACHE_REDIS_URL"] = environ.get("REDIS_URL").strip() -app.config["CACHE_DEFAULT_TIMEOUT"] = 86400 +app.config["CACHE_DEFAULT_TIMEOUT"] = 0 app.config["CACHE_SOURCE_CHECK"] = True #to allow session cookie to work on videos.watchpeopledie.tv diff --git a/files/helpers/cron.py b/files/helpers/cron.py index 98e7932f2..344844a99 100644 --- a/files/helpers/cron.py +++ b/files/helpers/cron.py @@ -401,4 +401,4 @@ def _set_top_poster_of_the_day_id(): send_notification(user.id, f":marseyjam: You're the Top Poster of the Day for the day of {t.year}-{t.month}-{t.day} :marseyjam:") badge_grant(badge_id=327, user=user) - cache.set("top_poster_of_the_day_id", user.id) + cache.set("top_poster_of_the_day_id", user.id, timeout=86400) diff --git a/files/routes/chat.py b/files/routes/chat.py index 9657f2497..3060fc1bb 100644 --- a/files/routes/chat.py +++ b/files/routes/chat.py @@ -35,7 +35,7 @@ messages = cache.get(f'messages') or {} online = {} typing = [] -cache.set('loggedin_chat', len(online), timeout=0) +cache.set('loggedin_chat', len(online), timeout=86400) def auth_required_socketio(f): def wrapper(*args, **kwargs): @@ -179,7 +179,7 @@ def refresh_online(): data = [list(online.values()), muted] emit("online", data, room="chat", broadcast=True) - cache.set('loggedin_chat', len(online), timeout=0) + cache.set('loggedin_chat', len(online), timeout=86400) @socketio.on('connect') @auth_required_socketio @@ -244,8 +244,8 @@ def delete(id, v): def close_running_threads(): - cache.set('messages', messages) - cache.set('muted', muted) + cache.set('messages', messages, timeout=86400) + cache.set('muted', muted, timeout=86400) atexit.register(close_running_threads) diff --git a/files/routes/front.py b/files/routes/front.py index b6432e836..2df31ef19 100644 --- a/files/routes/front.py +++ b/files/routes/front.py @@ -106,7 +106,7 @@ LIMITED_WPD_HOLES = {'aftermath', 'fights', 'gore', 'medical', 'request', 'selfh 'countryclub', 'highrollerclub', 'slavshit', 'sandshit'} -@cache.memoize() +@cache.memoize(timeout=86400) def frontlist(v=None, sort="hot", page=1, t="all", ids_only=True, filter_words='', gt=0, lt=0, hole=None, pins=True, effortposts_only=False, hide_cw=False): posts = g.db.query(Post) @@ -241,7 +241,7 @@ def random_user(v): return redirect(f"/@{u}") -@cache.memoize() +@cache.memoize(timeout=86400) def comment_idlist(v=None, page=1, sort="new", t="day", gt=0, lt=0): comments = g.db.query(Comment) \ .outerjoin(Comment.post) \ diff --git a/files/routes/jinja2.py b/files/routes/jinja2.py index 923175869..685719659 100644 --- a/files/routes/jinja2.py +++ b/files/routes/jinja2.py @@ -134,7 +134,7 @@ def bar_position(): return [int((vaxxed * 100) / total), int((zombie * 100) / total), vaxxed, zombie] -@cache.cached(make_cache_key=lambda:"emoji_count") +@cache.cached(make_cache_key=lambda:"emoji_count", timeout=86400) def emoji_count(): return g.db.query(Emoji).filter_by(submitter_id=None).count() diff --git a/files/routes/login.py b/files/routes/login.py index 74afa014a..598c388bc 100644 --- a/files/routes/login.py +++ b/files/routes/login.py @@ -138,7 +138,7 @@ def me(v): def logout(v): loggedin = cache.get('loggedin') or {} if session.get("lo_user") in loggedin: del loggedin[session["lo_user"]] - cache.set('loggedin', loggedin) + cache.set('loggedin', loggedin, timeout=86400) session.pop("lo_user", None) return {"message": "Logout successful!"} diff --git a/files/routes/routehelpers.py b/files/routes/routehelpers.py index 0c7ed0c50..39c620f18 100644 --- a/files/routes/routehelpers.py +++ b/files/routes/routehelpers.py @@ -30,7 +30,7 @@ def validate_formkey(u, formkey): if not formkey: return False return validate_hash(get_raw_formkey(u), formkey) -@cache.memoize() +@cache.memoize(timeout=86400) def get_alt_graph_ids(uid): alt_graph_cte = g.db.query(literal(uid).label('user_id')).select_from(Alt).cte('alt_graph', recursive=True) diff --git a/files/routes/special.py b/files/routes/special.py index d3ad71a2d..7456acbe1 100644 --- a/files/routes/special.py +++ b/files/routes/special.py @@ -76,7 +76,7 @@ # ORDER BY payout DESC, bets_won DESC, bets_total ASC; # """) -# @cache.memoize() +# @cache.memoize(timeout=86400) # def _special_leaderboard_get(): # result = g.db.execute(_special_leaderboard_query).all() # return result diff --git a/files/routes/static.py b/files/routes/static.py index 862d879fe..53f224fc3 100644 --- a/files/routes/static.py +++ b/files/routes/static.py @@ -47,7 +47,7 @@ def reddit_post(subreddit, v, path): def marseys_redirect(): return redirect("/emojis/marsey") -@cache.cached(make_cache_key=lambda kind, nsfw:f"emoji_list_{kind}_{nsfw}") +@cache.cached(make_cache_key=lambda kind, nsfw:f"emoji_list_{kind}_{nsfw}", timeout=86400) def get_emoji_list(kind, nsfw): emojis = g.db.query(Emoji).filter(Emoji.submitter_id == None, Emoji.kind == kind) @@ -85,7 +85,7 @@ def emoji_list(v, kind): -@cache.cached(make_cache_key=lambda nsfw:f"emojis_{nsfw}") +@cache.cached(make_cache_key=lambda nsfw:f"emojis_{nsfw}", timeout=86400) def get_emojis(nsfw): emojis = g.db.query(Emoji, User).join(User, Emoji.author_id == User.id).options(load_only( User.id, diff --git a/files/routes/users.py b/files/routes/users.py index 82239bcc2..19e7fd093 100644 --- a/files/routes/users.py +++ b/files/routes/users.py @@ -1006,7 +1006,7 @@ def u_username(v, username): total=total, is_following=is_following) -@cache.memoize() +@cache.memoize(timeout=86400) def userpagelisting(u, v=None, page=1, sort="new", t="all"): posts = g.db.query(Post).filter_by(author_id=u.id, profile_pinned=False).options(load_only(Post.id)) diff --git a/files/routes/wrappers.py b/files/routes/wrappers.py index 588aee2bc..fb99d357d 100644 --- a/files/routes/wrappers.py +++ b/files/routes/wrappers.py @@ -51,8 +51,8 @@ def calc_users(): loggedin = {k: v for k, v in loggedin.items() if (timestamp - v) < LOGGEDIN_ACTIVE_TIME} loggedout = {k: v for k, v in loggedout.items() if (timestamp - v[0]) < LOGGEDIN_ACTIVE_TIME} - cache.set(LOGGED_IN_CACHE_KEY, loggedin) - cache.set(LOGGED_OUT_CACHE_KEY, loggedout) + cache.set(LOGGED_IN_CACHE_KEY, loggedin, timeout=86400) + cache.set(LOGGED_OUT_CACHE_KEY, loggedout, timeout=86400) g.loggedin_counter = len(loggedin) g.loggedout_counter = len(loggedout)