gitlab-org--gitlab-foss/app/finders/notes_finder.rb

28 lines
889 B
Ruby
Raw Normal View History

class NotesFinder
2014-04-28 10:13:29 +00:00
FETCH_OVERLAP = 5.seconds
def execute(project, current_user, params)
target_type = params[:target_type]
target_id = params[:target_id]
# Default to 0 to remain compatible with old clients
last_fetched_at = Time.at(params.fetch(:last_fetched_at, 0).to_i)
2015-02-03 05:26:40 +00:00
notes =
case target_type
when "commit"
2015-02-06 18:21:48 +00:00
project.notes.for_commit_id(target_id).not_inline
2015-02-03 05:26:40 +00:00
when "issue"
2015-02-06 18:21:48 +00:00
project.issues.find(target_id).notes.inc_author
2015-02-03 05:26:40 +00:00
when "merge_request"
2015-02-06 18:21:48 +00:00
project.merge_requests.find(target_id).mr_and_commit_notes.inc_author
2015-02-03 05:26:40 +00:00
when "snippet", "project_snippet"
2015-02-06 18:21:48 +00:00
project.snippets.find(target_id).notes
2015-02-03 05:26:40 +00:00
else
raise 'invalid target_type'
end
2014-04-28 10:13:29 +00:00
# Use overlapping intervals to avoid worrying about race conditions
2015-02-06 18:21:48 +00:00
notes.where('updated_at > ?', last_fetched_at - FETCH_OVERLAP).fresh
end
end