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

Filter out old notes in NotesFinder

parent 7339464e
No related branches found
No related tags found
1 merge request!6949gitlab.com issue #229 - no_avatar.png path in coffee
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"
Loading
Loading
@@ -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
Loading
Loading
@@ -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
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