From 956faaa67d2c05d6f993fdee4d2c4a8a086036ec Mon Sep 17 00:00:00 2001 From: Jorge Manrubia Date: Tue, 14 Oct 2025 11:10:49 +0200 Subject: [PATCH] More fine-grained approach to listen for broadcasted refresh signals Only listen for collections actually involved in the view --- app/helpers/collections_helper.rb | 5 +++++ app/views/cards/_broadcasts.html.erb | 3 +++ app/views/cards/index.html.erb | 2 +- app/views/events/index.html.erb | 2 +- app/views/filters/_broadcasts.html.erb | 7 ------- 5 files changed, 10 insertions(+), 9 deletions(-) create mode 100644 app/helpers/collections_helper.rb create mode 100644 app/views/cards/_broadcasts.html.erb delete mode 100644 app/views/filters/_broadcasts.html.erb diff --git a/app/helpers/collections_helper.rb b/app/helpers/collections_helper.rb new file mode 100644 index 000000000..ac1debab4 --- /dev/null +++ b/app/helpers/collections_helper.rb @@ -0,0 +1,5 @@ +module CollectionsHelper + def referenced_collections_from(records) + Current.user.collections.where id: records.pluck(:collection_id).uniq + end +end diff --git a/app/views/cards/_broadcasts.html.erb b/app/views/cards/_broadcasts.html.erb new file mode 100644 index 000000000..d2404ae68 --- /dev/null +++ b/app/views/cards/_broadcasts.html.erb @@ -0,0 +1,3 @@ +<% referenced_collections_from(records).each do |collection| %> + <%= turbo_stream_from collection %> +<% end %> diff --git a/app/views/cards/index.html.erb b/app/views/cards/index.html.erb index 8b496c670..d700b363a 100644 --- a/app/views/cards/index.html.erb +++ b/app/views/cards/index.html.erb @@ -1,7 +1,7 @@ <% @page_title = @user_filtering.selected_collections_label %> <% turbo_exempts_page_from_cache %> -<%= render "filters/broadcasts", filter: @filter %> +<%= render "cards/broadcasts", records: @page.records %> <% content_for :head do %> <%= tag.meta property: "og:title", content: @page_title %> diff --git a/app/views/events/index.html.erb b/app/views/events/index.html.erb index d6a777d40..4868a5295 100644 --- a/app/views/events/index.html.erb +++ b/app/views/events/index.html.erb @@ -1,7 +1,7 @@ <% @page_title = "Home" %> <% @header_class = "header--events" %> -<%= render "filters/broadcasts", filter: @filter %> +<%= render "cards/broadcasts", records: @day_timeline.events %> <% content_for :header do %> <%= render "filters/menu" %> diff --git a/app/views/filters/_broadcasts.html.erb b/app/views/filters/_broadcasts.html.erb deleted file mode 100644 index a432280e6..000000000 --- a/app/views/filters/_broadcasts.html.erb +++ /dev/null @@ -1,7 +0,0 @@ -<% if filter.collections.any? %> - <% filter.collections.each do |collection| %> - <%= turbo_stream_from collection %> - <% end %> -<% else %> - <%= turbo_stream_from :collections %> -<% end %>