Commit 40a939a6 authored by Sean McGivern's avatar Sean McGivern

Merge branch 'rename-wrap-projects-cte' into 'master'

Rename wrap projects with CTE

See merge request gitlab-org/gitlab!24581
parents 2f8b2d23 4cffa1f8
......@@ -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