Rails API模式JBuilder分页

问题描述

我目前正在尝试处理包含9000条记录的大型数据集,并希望对其进行分页。我从未进行过分页工作,我知道Kaminari和Pagy可以做到这一点。我相信我需要用Kaminari提供的方法或Pagy来包装我的发现,但是我不确定在那之后应该如何处理Jbuilder视图。以下是我的find方法及其构建器的摘要。与会者哈希大约有9000条记录,导致加载超时或耗时约5分钟。我希望分页可以解决这个问题。

Controller
  class ConferencesController < ::ApplicationController
    def attendees
      @conference = Conference.find(attendee_params[:conference_id])
    end

    private

    def attendee_params
      params.permit(:conference_id)
    end
  end
end
View
json.full_name attendee.full_name
json.email attendee.email
json.requires_certification attendee.requires_certification

输出

{
  "conference": {
    "title": "Avengers Assemble","description": null,"starts_at": "2021-04-21T16:00:00.0000+0000","ends_at": "2021-04-21T16:45:00.0000+0000","attendees_count": 9002
  },"attendees": [
    {
      "full_name": "Steve Rogers","email": "blank@blank.com","requires_certification": true
    },{
      "full_name": "Bruce Banner","email": "denise.parisian@kirlin.biz","requires_certification": false
    },{
      "full_name": "THor Odinson","requires_certification": false
    }

解决方法

暂无找到可以解决该程序问题的有效方法,小编努力寻找整理中!

如果你已经找到好的解决方法,欢迎将解决方案带上本链接一起发送给小编。

小编邮箱:dio#foxmail.com (将#修改为@)

相关问答

依赖报错 idea导入项目后依赖报错,解决方案:https://blog....
错误1:代码生成器依赖和mybatis依赖冲突 启动项目时报错如下...
错误1:gradle项目控制台输出为乱码 # 解决方案:https://bl...
错误还原:在查询的过程中,传入的workType为0时,该条件不起...
报错如下,gcc版本太低 ^ server.c:5346:31: 错误:‘struct...