Commit 4cffa1f8 authored by Arturo Herrero's avatar Arturo Herrero

Rename wrap projects with CTE

The method is named wrap_authorized_projects_with_cte but we're actually
passing an arbitrary collection / query here.
parent d6bb8322
......@@ -45,7 +45,7 @@ class ProjectsFinder < UnionFinder
end
use_cte = params.delete(:use_cte)
collection = Project.wrap_authorized_projects_with_cte(collection) if use_cte
collection = Project.wrap_with_cte(collection) if use_cte
collection = filter_projects(collection)
sort(collection)
end
......
......@@ -548,8 +548,8 @@ class Project < ApplicationRecord
)
end
def self.wrap_authorized_projects_with_cte(collection)
cte = Gitlab::SQL::CTE.new(:authorized_projects, collection)
def self.wrap_with_cte(collection)
cte = Gitlab::SQL::CTE.new(:projects_cte, collection)
Project.with(cte.to_arel).from(cte.alias_to(Project.arel_table))
end
......
......@@ -120,7 +120,7 @@ module API
projects = current_user.can_read_all_resources? ? Project.all : current_user.authorized_projects
projects = projects.in_namespace(namespace.self_and_descendants)
projects_cte = Project.wrap_authorized_projects_with_cte(projects)
projects_cte = Project.wrap_with_cte(projects)
.eager_load_namespace_and_owner
.with_route
......
......@@ -3691,7 +3691,7 @@ describe Project do
end
end
describe '.wrap_authorized_projects_with_cte' do
describe '.wrap_with_cte' do
let!(:user) { create(:user) }
let!(:private_project) do
......@@ -3702,10 +3702,10 @@ describe Project do
let(:projects) { described_class.all.public_or_visible_to_user(user) }
subject { described_class.wrap_authorized_projects_with_cte(projects) }
subject { described_class.wrap_with_cte(projects) }
it 'wrapped query matches original' do
expect(subject.to_sql).to match(/^WITH "authorized_projects" AS/)
expect(subject.to_sql).to match(/^WITH "projects_cte" AS/)
expect(subject).to match_array(projects)
end
end
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment