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:
authorDouwe Maan <douwe@selenight.nl>2017-03-31 06:06:09 +0300
committerLuke "Jared" Bennett <lbennett@gitlab.com>2017-04-05 19:44:14 +0300
commit21e10888c3fc0fe545c0443cf0e23f593df847a4 (patch)
treec6c89c2ea2c75ffae4529ab4dceb937ce2f6299a /app/finders/notes_finder.rb
parentfe26b8af94e8e12a66249e28e34196a4f8b987c4 (diff)
Address review comments
Diffstat (limited to 'app/finders/notes_finder.rb')
-rw-r--r--app/finders/notes_finder.rb21
1 files changed, 13 insertions, 8 deletions
diff --git a/app/finders/notes_finder.rb b/app/finders/notes_finder.rb
index 855940762f3..c20bfb20171 100644
--- a/app/finders/notes_finder.rb
+++ b/app/finders/notes_finder.rb
@@ -20,9 +20,9 @@ class NotesFinder
end
def execute
- @notes = init_collection
- @notes = since_fetch_at(@params[:last_fetched_at], @notes) if @params[:last_fetched_at]
- @notes
+ notes = init_collection
+ notes = since_fetch_at(notes)
+ notes.fresh
end
def target
@@ -56,7 +56,7 @@ class NotesFinder
def notes_of_any_type
types = %w(commit issue merge_request snippet)
note_relations = types.map { |t| notes_for_type(t) }
- note_relations.map! { |notes| search(@params[:search], notes) } if @params[:search]
+ note_relations.map! { |notes| search(notes) }
UnionFinder.new.find_union(note_relations, Note)
end
@@ -98,16 +98,21 @@ class NotesFinder
#
# This method uses ILIKE on PostgreSQL and LIKE on MySQL.
#
- def search(query, notes_relation = @notes)
+ def search(query, notes)
+ query = @params[:search]
+ return unless query
+
pattern = "%#{query}%"
- notes_relation.where(Note.arel_table[:note].matches(pattern))
+ notes.where(Note.arel_table[:note].matches(pattern))
end
# Notes changed since last fetch
# Uses overlapping intervals to avoid worrying about race conditions
- def since_fetch_at(fetch_time, notes_relation = @notes)
+ def since_fetch_at(notes)
+ return notes unless @params[:last_fetched_at]
+
# Default to 0 to remain compatible with old clients
last_fetched_at = Time.at(@params.fetch(:last_fetched_at, 0).to_i)
- notes_relation.where('updated_at > ?', last_fetched_at - FETCH_OVERLAP).fresh
+ notes.updated_after(last_fetched_at - FETCH_OVERLAP)
end
end