Skip to content
Snippets Groups Projects
Commit 0b615eb0 authored by Jacob Vosmaer's avatar Jacob Vosmaer
Browse files

Filter out old notes in NotesFinder

parent 7339464e
No related branches found
No related tags found
No related merge requests found
class NotesFinder class NotesFinder
FETCH_OVERLAP = 5.seconds
def execute(project, current_user, params) def execute(project, current_user, params)
target_type = params[:target_type] target_type = params[:target_type]
target_id = params[:target_id] target_id = params[:target_id]
last_fetched_at = params.fetch(:last_fetched_at)
   
case target_type notes = case target_type
when "commit" when "commit"
project.notes.for_commit_id(target_id).not_inline.fresh project.notes.for_commit_id(target_id).not_inline.fresh
when "issue" when "issue"
Loading
@@ -15,5 +18,8 @@ class NotesFinder
Loading
@@ -15,5 +18,8 @@ class NotesFinder
else else
raise 'invalid target_type' raise 'invalid target_type'
end end
# Use overlapping intervals to avoid worrying about race conditions
notes.where('updated_at > ?', last_fetched_at - FETCH_OVERLAP)
end end
end end
Loading
@@ -27,5 +27,12 @@ describe NotesFinder do
Loading
@@ -27,5 +27,12 @@ describe NotesFinder do
params = { target_id: commit.id, target_type: 'invalid' } params = { target_id: commit.id, target_type: 'invalid' }
expect { NotesFinder.new.execute(project, user, params) }.to raise_error('invalid target_type') expect { NotesFinder.new.execute(project, user, params) }.to raise_error('invalid target_type')
end 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
end end
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment