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

28 lines
909 B
Ruby
Raw Normal View History

class NotesFinder
2014-04-28 06:13:29 -04: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 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
end
end