【发布时间】:2019-08-15 17:11:58
【问题描述】:
我的视图需要在控制器中生成 JSON,当扩展更大的信息集时,生成 JSON 需要很长时间。我的问题是 Heroku 在超时之前有 30 秒的加载时间限制,对于更大的数据集,它会超时。
我已经实现了 Redis to go 和 Sidekiq,它帮助我在应用程序上实现了不同的功能。
当有较大的数据集时,显示视图也会分页。不确定我最好的选择是什么。
我正在考虑创建一个中间页面,同时使用 Sidkiq 异步创建 JSON,然后在创建 JSON 时提醒用户,然后允许用户在加载后转到显示视图,这是一个不错的选择,但随后我想我使用 Kaminari Gem 的分页会有问题。
就像我说的,我已经在使用 Sidekiq,所以我认为这将是我的最佳选择。
def show
# @salesforce = true if @account.Name != nil
@audit_report = audit_report
@measures_updated = MeasuresUpdated.new(audit_report: @audit_report)
@measures_updated = @measures_updated.check_measures_updated
@page_title = "Report based on \"#{@audit_report.name}\""
@context = ShowAuditReportContext.new(
user: current_user,
audit_report: @audit_report).audit_report_as_json
@context_measure_selections = @context[:audit_report][:measure_selections]
@context_measure_selections_array = @context[:audit_report][:measure_selections].to_a
@paginatable_array = Kaminari.paginate_array(@context_measure_selections_array).page(params[:page]).per(15)
结束
这是在控制器中 @context 是问题所在,后端中有很多计算放置在不同的类中,需要很长时间才能加载。
我希望用户访问显示页面而不会因服务器限制而超时。
【问题讨论】:
标签: ruby-on-rails asynchronous heroku pagination sidekiq