Commit 0b615eb0 authored by Jacob Vosmaer's avatar Jacob Vosmaer

Filter out old notes in NotesFinder

parent 7339464e
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
......@@ -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
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