From bf3bd577e0fa753b5b7976a73d4c480b45debeac Mon Sep 17 00:00:00 2001 From: Camil Staps Date: Mon, 28 Jan 2019 19:02:03 +0100 Subject: Rewrite StarredProjectsFinder to use ProjectsFinder --- app/controllers/users_controller.rb | 2 +- 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 -- cgit v1.2.3