diff options
author | Camil Staps <info@camilstaps.nl> | 2019-01-28 19:02:03 +0100 |
---|---|---|
committer | Camil Staps <info@camilstaps.nl> | 2019-08-07 20:49:15 +0200 |
commit | bf3bd577e0fa753b5b7976a73d4c480b45debeac (patch) | |
tree | f1404b903b403083340e42b6b58d099fb2f42785 | |
parent | a052f68116363109b5d49c9738e711a12257ac7d (diff) | |
download | gitlab-ce-bf3bd577e0fa753b5b7976a73d4c480b45debeac.tar.gz |
Rewrite StarredProjectsFinder to use ProjectsFinder
-rw-r--r-- | app/controllers/users_controller.rb | 2 | ||||
-rw-r--r-- | app/finders/starred_projects_finder.rb | 33 |
2 files changed, 5 insertions, 30 deletions
diff --git a/app/controllers/users_controller.rb b/app/controllers/users_controller.rb index 36687e3606e..bc1587e6be0 100644 --- a/app/controllers/users_controller.rb +++ b/app/controllers/users_controller.rb @@ -134,7 +134,7 @@ class UsersController < ApplicationController end def starred_projects - StarredProjectsFinder.new(user).execute(current_user) + StarredProjectsFinder.new(user, current_user: current_user).execute end def contributions_calendar diff --git a/app/finders/starred_projects_finder.rb b/app/finders/starred_projects_finder.rb index e5eeb19a8f3..5d0c6820a26 100644 --- a/app/finders/starred_projects_finder.rb +++ b/app/finders/starred_projects_finder.rb @@ -1,33 +1,8 @@ # frozen_string_literal: true -class StarredProjectsFinder < UnionFinder - def initialize(user) - @user = user - end - - # Finds the projects "@user" starred, limited to either public projects or - # projects visible to the given user. - # - # current_user - When given the list of the projects is limited to those only - # visible by this user. - # - # Returns an ActiveRecord::Relation. - # rubocop: disable CodeReuse/ActiveRecord - def execute(current_user = nil) - segments = all_projects(current_user) - - find_union(segments, Project).includes(:namespace).order_id_desc - end - # rubocop: enable CodeReuse/ActiveRecord - - private - - def all_projects(current_user) - projects = [] - - projects << @user.starred_projects.visible_to_user(current_user) if current_user - projects << @user.starred_projects.public_to_user(current_user) - - projects +class StarredProjectsFinder < ProjectsFinder + def initialize(user, params: {}, current_user: nil) + project_ids = user.starred_projects.includes(:creator).select(:id) + super(params: params, current_user: current_user, project_ids_relation: project_ids) end end |