2014-02-25 12:15:08 -05:00
|
|
|
class NotesFinder
|
2014-04-28 06:13:29 -04:00
|
|
|
FETCH_OVERLAP = 5.seconds
|
|
|
|
|
2014-02-25 12:15:08 -05:00
|
|
|
def execute(project, current_user, params)
|
|
|
|
target_type = params[:target_type]
|
|
|
|
target_id = params[:target_id]
|
2014-04-28 10:37:19 -04: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 12:15:08 -05:00
|
|
|
|
2015-02-03 00:26:40 -05:00
|
|
|
notes =
|
|
|
|
case target_type
|
|
|
|
when "commit"
|
2015-02-06 13:21:48 -05:00
|
|
|
project.notes.for_commit_id(target_id).not_inline
|
2015-02-03 00:26:40 -05:00
|
|
|
when "issue"
|
2015-11-17 06:16:16 -05:00
|
|
|
project.issues.find(target_id).notes.nonawards.inc_author
|
2015-02-03 00:26:40 -05:00
|
|
|
when "merge_request"
|
2015-11-17 06:16:16 -05:00
|
|
|
project.merge_requests.find(target_id).mr_and_commit_notes.nonawards.inc_author
|
2015-02-03 00:26:40 -05:00
|
|
|
when "snippet", "project_snippet"
|
2015-02-06 13:21:48 -05:00
|
|
|
project.snippets.find(target_id).notes
|
2015-02-03 00:26:40 -05:00
|
|
|
else
|
|
|
|
raise 'invalid target_type'
|
|
|
|
end
|
2014-04-28 06:13:29 -04:00
|
|
|
|
|
|
|
# Use overlapping intervals to avoid worrying about race conditions
|
2015-02-06 13:21:48 -05:00
|
|
|
notes.where('updated_at > ?', last_fetched_at - FETCH_OVERLAP).fresh
|
2014-02-25 12:15:08 -05:00
|
|
|
end
|
|
|
|
end
|