-
Notifications
You must be signed in to change notification settings - Fork 42
Expand file tree
/
Copy pathuser_app_datum_controller.rb
More file actions
41 lines (36 loc) · 1.11 KB
/
user_app_datum_controller.rb
File metadata and controls
41 lines (36 loc) · 1.11 KB
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
# frozen_string_literal: true
module Api
module V8
class UserAppDatumController < Api::V8::BaseController
skip_authorization_check
def index
only_admins!
if params[:after]
timestamp = Time.zone.parse(params[:after])
data = UserAppDatum.where('created_at >= ? OR updated_at >= ?', timestamp, timestamp)
return render json: data
end
headers['X-Accel-Buffering'] = 'no'
headers['Cache-Control'] = 'no-cache'
headers['Content-Type'] = 'application/json'
# headers['Transfer-Encoding'] = 'chunked'
headers.delete('Content-Length')
self.response_body = build_json_enumerator(UserAppDatum)
# render json: UserAppDatum.all
end
private
def build_json_enumerator(query)
first = true
Enumerator.new do |yielder|
yielder << '['
query.find_each do |datum|
yielder << ',' unless first
yielder << datum.to_json
first = false
end
yielder << ']'
end
end
end
end
end