From 49b9bcbdfdcdcf90467f9862818ee63aa940ee2a Mon Sep 17 00:00:00 2001 From: Caio Almeida <117518+caiosba@users.noreply.github.com> Date: Thu, 4 Jul 2024 09:47:23 -0300 Subject: [PATCH] Try to make sure that clusters center is never null. (#1942) And/or that at least clusters without a center are never returned. We don't know exactly in which cases this crash happens. So this commit approaches it in two different ways: * For a given feed, only return clusters that have a center, by adding a `INNER JOIN project_medias` clause to the feed clusters query. * For the `ClusterType` GraphQL endpoint, fallback to the cluster model `center` method, which already falls back to the first item of the cluster if the center is not present anymore. Fixes CV2-4850. --- app/graph/types/cluster_type.rb | 6 ------ app/models/feed.rb | 2 +- 2 files changed, 1 insertion(+), 7 deletions(-) diff --git a/app/graph/types/cluster_type.rb b/app/graph/types/cluster_type.rb index 092d15a46c..f5859e039f 100644 --- a/app/graph/types/cluster_type.rb +++ b/app/graph/types/cluster_type.rb @@ -18,12 +18,6 @@ def fact_checks_count field :center, ProjectMediaType, null: true - def center - RecordLoader - .for(ProjectMedia) - .load(object.project_media_id) - end - field :first_item_at, GraphQL::Types::Int, null: true def first_item_at diff --git a/app/models/feed.rb b/app/models/feed.rb index 3fd3b5b618..05a652024f 100755 --- a/app/models/feed.rb +++ b/app/models/feed.rb @@ -140,7 +140,7 @@ def clusters_count(args = {}) def filtered_clusters(args = {}) team_ids = args[:team_ids] channels = args[:channels] - query = self.clusters + query = self.clusters.joins(:project_media) # Filter by workspace query = query.where.not("ARRAY[?] && team_ids", self.team_ids - team_ids.to_a.map(&:to_i)) if !team_ids.blank? && team_ids != self.team_ids