Welcome to mirror list, hosted at ThFree Co, Russian Federation.

gitlab.com/gitlab-org/gitlab-foss.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorJan Provaznik <jprovaznik@gitlab.com>2018-03-06 15:40:52 +0300
committerJan Provaznik <jprovaznik@gitlab.com>2018-03-06 15:40:52 +0300
commitefb5b2dd2275db65a8cab55b11efbea539b63848 (patch)
tree5d05e2aed76b0953fc5dd0d22fba0a1c3fb07d40
parentce12b60e97a9a4518dd99b990e20e55ec8da22bc (diff)
Reverted split into sub-queries for notes countjprovazn-revert-union-split
-rw-r--r--app/finders/notes_finder.rb12
-rw-r--r--lib/gitlab/project_search_results.rb18
-rw-r--r--spec/finders/notes_finder_spec.rb12
-rw-r--r--spec/lib/gitlab/project_search_results_spec.rb18
4 files changed, 8 insertions, 52 deletions
diff --git a/app/finders/notes_finder.rb b/app/finders/notes_finder.rb
index 35f4ff2f62f..33ee1e975b9 100644
--- a/app/finders/notes_finder.rb
+++ b/app/finders/notes_finder.rb
@@ -48,23 +48,11 @@ class NotesFinder
def init_collection
if target
notes_on_target
- elsif target_type
- notes_of_target_type
else
notes_of_any_type
end
end
- def notes_of_target_type
- notes = notes_for_type(target_type)
-
- search(notes)
- end
-
- def target_type
- @params[:target_type]
- end
-
def notes_of_any_type
types = %w(commit issue merge_request snippet)
note_relations = types.map { |t| notes_for_type(t) }
diff --git a/lib/gitlab/project_search_results.rb b/lib/gitlab/project_search_results.rb
index 29277ec6481..6a3aa9a7ca2 100644
--- a/lib/gitlab/project_search_results.rb
+++ b/lib/gitlab/project_search_results.rb
@@ -30,17 +30,7 @@ module Gitlab
end
def limited_notes_count
- return @limited_notes_count if defined?(@limited_notes_count)
-
- types = %w(issue merge_request commit snippet)
- @limited_notes_count = 0
-
- types.each do |type|
- @limited_notes_count += notes_finder(type).limit(count_limit).count
- break if @limited_notes_count >= count_limit
- end
-
- @limited_notes_count
+ @notes_count ||= notes.limit(count_limit).count
end
def wiki_blobs_count
@@ -117,11 +107,7 @@ module Gitlab
end
def notes
- @notes ||= notes_finder(nil)
- end
-
- def notes_finder(type)
- NotesFinder.new(project, @current_user, search: query, target_type: type).execute.user.order('updated_at DESC')
+ @notes ||= NotesFinder.new(project, @current_user, search: query).execute.user.order('updated_at DESC')
end
def commits
diff --git a/spec/finders/notes_finder_spec.rb b/spec/finders/notes_finder_spec.rb
index f1ae2c7ab65..7b43494eea2 100644
--- a/spec/finders/notes_finder_spec.rb
+++ b/spec/finders/notes_finder_spec.rb
@@ -75,18 +75,6 @@ describe NotesFinder do
end
end
- context 'for target type' do
- let(:project) { create(:project, :repository) }
- let!(:note1) { create :note_on_issue, project: project }
- let!(:note2) { create :note_on_commit, project: project }
-
- it 'finds only notes for the selected type' do
- notes = described_class.new(project, user, target_type: 'issue').execute
-
- expect(notes).to eq([note1])
- end
- end
-
context 'for target' do
let(:project) { create(:project, :repository) }
let(:note1) { create :note_on_commit, project: project }
diff --git a/spec/lib/gitlab/project_search_results_spec.rb b/spec/lib/gitlab/project_search_results_spec.rb
index c46bb8edebf..f152fee6cce 100644
--- a/spec/lib/gitlab/project_search_results_spec.rb
+++ b/spec/lib/gitlab/project_search_results_spec.rb
@@ -306,29 +306,23 @@ describe Gitlab::ProjectSearchResults do
describe '#limited_notes_count' do
let(:project) { create(:project, :public) }
- let(:note) { create(:note_on_issue, project: project) }
- let(:results) { described_class.new(user, project, note.note) }
+ let!(:note) { create(:note_on_issue, project: project, note: 'foo1') }
+ let!(:note2) { create(:note_on_issue, project: project, note: 'foo2') }
+ let(:results) { described_class.new(user, project, 'foo') }
context 'when count_limit is lower than total amount' do
before do
allow(results).to receive(:count_limit).and_return(1)
end
- it 'calls note finder once to get the limited amount of notes' do
- expect(results).to receive(:notes_finder).once.and_call_original
+ it 'returns the limited amount of notes' do
expect(results.limited_notes_count).to eq(1)
end
end
context 'when count_limit is higher than total amount' do
- it 'calls note finder multiple times to get the limited amount of notes' do
- project = create(:project, :public)
- note = create(:note_on_issue, project: project)
-
- results = described_class.new(user, project, note.note)
-
- expect(results).to receive(:notes_finder).exactly(4).times.and_call_original
- expect(results.limited_notes_count).to eq(1)
+ it 'returns count of all notes' do
+ expect(results.limited_notes_count).to eq(2)
end
end
end