Skip to content

Commit

Permalink
Try to make sure that clusters center is never null. (#1942)
Browse files Browse the repository at this point in the history
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.
  • Loading branch information
caiosba committed Jul 4, 2024
1 parent dbea89a commit a59b2ff
Show file tree
Hide file tree
Showing 2 changed files with 1 addition and 7 deletions.
6 changes: 0 additions & 6 deletions app/graph/types/cluster_type.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
2 changes: 1 addition & 1 deletion app/models/feed.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down

0 comments on commit a59b2ff

Please sign in to comment.