From 50531d3b6b1ca4c9e0d6479f219358751ad095b9 Mon Sep 17 00:00:00 2001 From: Karina Kwiatek Date: Fri, 5 May 2023 16:45:42 +0200 Subject: [PATCH 1/2] Cache notifications dropdown based on `notifications_updated_at` --- app/models/user/notification_methods.rb | 1 + app/views/navigation/_desktop.html.haml | 4 +++- app/views/navigation/_main.html.haml | 3 +-- 3 files changed, 5 insertions(+), 3 deletions(-) diff --git a/app/models/user/notification_methods.rb b/app/models/user/notification_methods.rb index db7e5018..41ad8a2e 100644 --- a/app/models/user/notification_methods.rb +++ b/app/models/user/notification_methods.rb @@ -14,4 +14,5 @@ module User::NotificationMethods end def notification_cache_key = "#{cache_key}/unread_notification_count-#{notifications_updated_at}" + def notification_dropdown_cache_key = "#{cache_key}/notification_dropdown-#{notifications_updated_at}" end diff --git a/app/views/navigation/_desktop.html.haml b/app/views/navigation/_desktop.html.haml index 93a6a027..42eb0f8f 100644 --- a/app/views/navigation/_desktop.html.haml +++ b/app/views/navigation/_desktop.html.haml @@ -31,7 +31,9 @@ %span.badge= notification_count .dropdown-menu.dropdown-menu-end.notification-dropdown %turbo-frame#notifications-dropdown-list - = render "navigation/dropdown/notifications", notifications:, notification_count: nil + - Rails.cache.fetch current_user.notification_dropdown_cache_key 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') } %a.nav-link{ href: "#", name: "toggle-all-ask", data: { bs_target: "#modal-ask-followers", bs_toggle: :modal, hotkey: "n" } } %i.fa.fa-pencil-square-o diff --git a/app/views/navigation/_main.html.haml b/app/views/navigation/_main.html.haml index a58e50b1..72c03da0 100644 --- a/app/views/navigation/_main.html.haml +++ b/app/views/navigation/_main.html.haml @@ -1,8 +1,7 @@ :ruby - notifications = Notification.for(current_user).where(new: true).includes([:target]).limit(4) inbox_count = current_user.unread_inbox_count notification_count = current_user.unread_notification_count -= render "navigation/desktop", notifications:, inbox_count:, notification_count: += render "navigation/desktop", inbox_count:, notification_count: = render "navigation/mobile", inbox_count:, notification_count: = render "modal/ask" From 7dc25ba841c722931795bc1e031383f838b0f0a4 Mon Sep 17 00:00:00 2001 From: Karina Kwiatek Date: Sun, 7 May 2023 12:51:40 +0200 Subject: [PATCH 2/2] Appease the robot dog --- app/views/navigation/_desktop.html.haml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/app/views/navigation/_desktop.html.haml b/app/views/navigation/_desktop.html.haml index 42eb0f8f..35ee9a4f 100644 --- a/app/views/navigation/_desktop.html.haml +++ b/app/views/navigation/_desktop.html.haml @@ -33,7 +33,7 @@ %turbo-frame#notifications-dropdown-list - Rails.cache.fetch current_user.notification_dropdown_cache_key do - notifications = Notification.for(current_user).where(new: true).includes([:target]).limit(4) - = render 'navigation/dropdown/notifications', notifications:, size: "desktop" + = 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') } %a.nav-link{ href: "#", name: "toggle-all-ask", data: { bs_target: "#modal-ask-followers", bs_toggle: :modal, hotkey: "n" } } %i.fa.fa-pencil-square-o