Commit 2bd9d0c6 authored by Vijay Hawoldar's avatar Vijay Hawoldar

Check for feature status in SnippetsFinder

So that execution is halted when finding
project snippets for a project that is
disabled
parent 796cd50d
...@@ -61,9 +61,11 @@ class SnippetsFinder < UnionFinder ...@@ -61,9 +61,11 @@ class SnippetsFinder < UnionFinder
def execute def execute
# The snippet query can be expensive, therefore if the # The snippet query can be expensive, therefore if the
# author or project params have been passed and they don't # author or project params have been passed and they don't
# exist, it's better to return # exist, or if a Project has been passed and has snippets
# disabled, it's better to return
return Snippet.none if author.nil? && params[:author].present? return Snippet.none if author.nil? && params[:author].present?
return Snippet.none if project.nil? && params[:project].present? return Snippet.none if project.nil? && params[:project].present?
return Snippet.none if project && !project.feature_available?(:snippets, current_user)
items = init_collection items = init_collection
items = by_ids(items) items = by_ids(items)
......
---
title: Improve SnippetsFinder performance with disabled project snippets
merge_request: 26295
author:
type: performance
...@@ -284,6 +284,17 @@ describe SnippetsFinder do ...@@ -284,6 +284,17 @@ describe SnippetsFinder do
expect(described_class.new(user).execute).to contain_exactly(private_personal_snippet, internal_personal_snippet, public_personal_snippet) expect(described_class.new(user).execute).to contain_exactly(private_personal_snippet, internal_personal_snippet, public_personal_snippet)
end end
end end
context 'when project snippets are disabled' do
it 'returns quickly' do
disabled_snippets_project = create(:project, :snippets_disabled)
finder = described_class.new(user, project: disabled_snippets_project.id)
expect(finder).not_to receive(:init_collection)
expect(Snippet).to receive(:none).and_call_original
expect(finder.execute).to be_empty
end
end
end end
it_behaves_like 'snippet visibility' it_behaves_like 'snippet visibility'
......
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