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:
-rw-r--r--app/finders/notes_finder.rb8
-rw-r--r--spec/finders/notes_finder_spec.rb7
2 files changed, 14 insertions, 1 deletions
diff --git a/app/finders/notes_finder.rb b/app/finders/notes_finder.rb
index 4e80bd81757..38d78f3a2d5 100644
--- a/app/finders/notes_finder.rb
+++ b/app/finders/notes_finder.rb
@@ -1,9 +1,12 @@
class NotesFinder
+ FETCH_OVERLAP = 5.seconds
+
def execute(project, current_user, params)
target_type = params[:target_type]
target_id = params[:target_id]
+ last_fetched_at = params.fetch(:last_fetched_at)
- case target_type
+ notes = case target_type
when "commit"
project.notes.for_commit_id(target_id).not_inline.fresh
when "issue"
@@ -15,5 +18,8 @@ class NotesFinder
else
raise 'invalid target_type'
end
+
+ # Use overlapping intervals to avoid worrying about race conditions
+ notes.where('updated_at > ?', last_fetched_at - FETCH_OVERLAP)
end
end
diff --git a/spec/finders/notes_finder_spec.rb b/spec/finders/notes_finder_spec.rb
index 27eaba8dfa1..ffd3f5db815 100644
--- a/spec/finders/notes_finder_spec.rb
+++ b/spec/finders/notes_finder_spec.rb
@@ -27,5 +27,12 @@ describe NotesFinder do
params = { target_id: commit.id, target_type: 'invalid' }
expect { NotesFinder.new.execute(project, user, params) }.to raise_error('invalid target_type')
end
+
+ it 'filters out old notes' do
+ note2.update_attribute(:updated_at, 2.hours.ago)
+ params = { target_id: commit.id, target_type: 'commit', last_fetched_at: 1.hour.ago }
+ notes = NotesFinder.new.execute(project, user, params)
+ notes.should eq([note1])
+ end
end
end