Skip to content

try streaming user app datum json #546

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 4 commits into
base: master
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
23 changes: 22 additions & 1 deletion app/controllers/api/v8/user_app_datum_controller.rb
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,28 @@ def index
return render json: data
end

render json: UserAppDatum.all
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
Expand Down