blob: 588fc85ff771d4dcdce9a57a2a6e2a83102d6ceb (
plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
|
# frozen_string_literal: true
class Projects::MergeRequests::ContentController < Projects::MergeRequests::ApplicationController
# @merge_request.check_mergeability is not executed here since
# widget serializer calls it via mergeable? method
# but we might want to call @merge_request.check_mergeability
# for other types of serialization
before_action :close_merge_request_if_no_source_project
before_action :set_polling_header
around_action :allow_gitaly_ref_name_caching
FAST_POLLING_INTERVAL = 10.seconds.in_milliseconds
SLOW_POLLING_INTERVAL = 5.minutes.in_milliseconds
urgency :low, [
:widget,
:cached_widget
]
def widget
respond_to do |format|
format.json do
render json: serializer(MergeRequestPollWidgetEntity)
end
end
end
def cached_widget
respond_to do |format|
format.json do
render json: serializer(MergeRequestPollCachedWidgetEntity)
end
end
end
private
def set_polling_header
interval = merge_request.open? ? FAST_POLLING_INTERVAL : SLOW_POLLING_INTERVAL
Gitlab::PollingInterval.set_header(response, interval: interval)
end
def serializer(entity)
serializer = MergeRequestSerializer.new(current_user: current_user, project: merge_request.project)
serializer.represent(merge_request, {}, entity)
end
end
|