2014-02-25 17:15:08 +00:00
|
|
|
class NotesFinder
|
2014-04-28 10:13:29 +00:00
|
|
|
FETCH_OVERLAP = 5.seconds
|
|
|
|
|
2014-02-25 17:15:08 +00:00
|
|
|
def execute(project, current_user, params)
|
|
|
|
target_type = params[:target_type]
|
|
|
|
target_id = params[:target_id]
|
2014-04-28 14:37:19 +00:00
|
|
|
# Default to 0 to remain compatible with old clients
|
|
|
|
last_fetched_at = Time.at(params.fetch(:last_fetched_at, 0).to_i)
|
2014-02-25 17:15:08 +00:00
|
|
|
|
2015-02-03 05:26:40 +00:00
|
|
|
notes =
|
|
|
|
case target_type
|
|
|
|
when "commit"
|
2016-05-10 22:41:46 +00:00
|
|
|
project.notes.for_commit_id(target_id).non_diff_notes
|
2015-02-03 05:26:40 +00:00
|
|
|
when "issue"
|
2015-11-17 11:16:16 +00:00
|
|
|
project.issues.find(target_id).notes.nonawards.inc_author
|
2015-02-03 05:26:40 +00:00
|
|
|
when "merge_request"
|
2015-11-17 11:16:16 +00:00
|
|
|
project.merge_requests.find(target_id).mr_and_commit_notes.nonawards.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
|
2014-02-25 17:15:08 +00:00
|
|
|
end
|
|
|
|
end
|