diff options
author | Thong Kuah <tkuah@gitlab.com> | 2018-12-11 18:13:29 +1300 |
---|---|---|
committer | Thong Kuah <tkuah@gitlab.com> | 2018-12-17 09:51:53 +1300 |
commit | f82c9dbe44d5d003dbeb084f07615ba26c2294b6 (patch) | |
tree | 4b4a803a08c29b969797937af47a30ac0ef0b1a8 /app/finders | |
parent | 2ad5f999e95ed0627e2c8aea9da670b7da559bab (diff) | |
download | gitlab-ce-f82c9dbe44d5d003dbeb084f07615ba26c2294b6.tar.gz |
Use finder to decide to show note to user
Given the note is about how to interpret ancestor clusters, use the
finder which actually knows if there are any ancestor clusters to find
out if the note should be shown, rather than passing the same info via a
view to a helper
Added note about Kaminari.paginate_array
Link to followup issue too
Diffstat (limited to 'app/finders')
-rw-r--r-- | app/finders/cluster_ancestors_finder.rb | 11 |
1 files changed, 10 insertions, 1 deletions
diff --git a/app/finders/cluster_ancestors_finder.rb b/app/finders/cluster_ancestors_finder.rb index 586fceb258a..2f9709ee057 100644 --- a/app/finders/cluster_ancestors_finder.rb +++ b/app/finders/cluster_ancestors_finder.rb @@ -1,6 +1,8 @@ # frozen_string_literal: true class ClusterAncestorsFinder + include Gitlab::Utils::StrongMemoize + def initialize(clusterable, current_user) @clusterable = clusterable @current_user = current_user @@ -12,6 +14,10 @@ class ClusterAncestorsFinder clusterable.clusters + ancestor_clusters end + def has_ancestor_clusters? + ancestor_clusters.any? + end + private attr_reader :clusterable, :current_user @@ -20,7 +26,10 @@ class ClusterAncestorsFinder Ability.allowed?(current_user, :read_cluster, clusterable) end + # This unfortunately returns an Array, not a Relation! def ancestor_clusters - Clusters::Cluster.ancestor_clusters_for_clusterable(clusterable) + strong_memoize(:ancestor_clusters) do + Clusters::Cluster.ancestor_clusters_for_clusterable(clusterable) + end end end |