From 134c575e403f7edfdfc26e197422fd07242e47d7 Mon Sep 17 00:00:00 2001 From: Andreas Nedbal Date: Thu, 25 Jan 2024 21:15:04 +0100 Subject: [PATCH] Add missing expire times to cache keys --- app/models/user/ban_methods.rb | 2 +- app/models/user/inbox_methods.rb | 2 +- app/models/user/notification_methods.rb | 2 +- app/views/navigation/_desktop.html.haml | 2 +- 4 files changed, 4 insertions(+), 4 deletions(-) diff --git a/app/models/user/ban_methods.rb b/app/models/user/ban_methods.rb index 2fab74a3..90cb62d6 100644 --- a/app/models/user/ban_methods.rb +++ b/app/models/user/ban_methods.rb @@ -6,7 +6,7 @@ module User::BanMethods end def banned? - Rails.cache.fetch("#{cache_key}/banned") do + Rails.cache.fetch("#{cache_key}/banned", expires_in: 6.hours) do bans.current.count.positive? end end diff --git a/app/models/user/inbox_methods.rb b/app/models/user/inbox_methods.rb index 8e3b00fe..54dd89ef 100644 --- a/app/models/user/inbox_methods.rb +++ b/app/models/user/inbox_methods.rb @@ -14,7 +14,7 @@ module User::InboxMethods end def unread_inbox_count - Rails.cache.fetch(inbox_cache_key) do + Rails.cache.fetch(inbox_cache_key, expires_in: 12.hours) do count = Inbox.where(new: true, user_id: id).count(:id) # Returning +nil+ here in order to not display a counter diff --git a/app/models/user/notification_methods.rb b/app/models/user/notification_methods.rb index 41ad8a2e..10738516 100644 --- a/app/models/user/notification_methods.rb +++ b/app/models/user/notification_methods.rb @@ -2,7 +2,7 @@ module User::NotificationMethods def unread_notification_count - Rails.cache.fetch(notification_cache_key) do + Rails.cache.fetch(notification_cache_key, expires_in: 12.hours) do count = Notification.for(self).where(new: true).count(:id) # Returning +nil+ here in order to not display a counter diff --git a/app/views/navigation/_desktop.html.haml b/app/views/navigation/_desktop.html.haml index 267c59ff..ceb1fd08 100644 --- a/app/views/navigation/_desktop.html.haml +++ b/app/views/navigation/_desktop.html.haml @@ -26,7 +26,7 @@ = render "navigation/icons/notifications", notification_count: .dropdown-menu.dropdown-menu-end.notification-dropdown %turbo-frame#notifications-dropdown-list - - cache current_user.notification_dropdown_cache_key do + - cache current_user.notification_dropdown_cache_key, expires_in: 12.hours do - notifications = Notification.for(current_user).where(new: true).includes([:target]).limit(4) = render "navigation/dropdown/notifications", notifications:, size: "desktop" %li.nav-item.d-none.d-sm-block{ data: { bs_toggle: 'tooltip', bs_placement: 'bottom' }, title: t('.ask_question') }