【问题标题】:How to reduce size of data in laravel for ajax response?如何减少laravel中的数据大小以进行ajax响应?
【发布时间】:2021-05-02 04:13:53
【问题描述】:

我正在从数据库中获取数据,该数据库从数据库中返回了近 5000 条记录。当我通过网络看到资源大小时,它是 10 mb 的大小。

这张表有将近五十列。有什么办法可以减小浏览器网络选项卡中显示的大小?

这里是查询

$consignments = Consignment::query();
$consignments->where('delivery_run_id', null);
  
$consignments = $consignments->orderBy('id', 'desc')->limit(5000)->get();

return Response::json(['status' => 'success', 'consignment' => $consignments]);

我尝试使用select() 但没有效果

【问题讨论】:

标签: laravel eloquent laravel-5.8


【解决方案1】:

我是这样解决的。我只是选择了 ajax 响应所需的列并忽略了所有其他列,现在我成功地将数据从 10mb 减少到 2.5mb

【讨论】:

    【解决方案2】:

    试试这个

    $consignments = $consignments->orderBy('id', 'desc')->limit(5000)->select(['column one','column two','column three']); 
    

    【讨论】:

      猜你喜欢
      • 2017-05-11
      • 2010-12-15
      • 2016-11-11
      • 2012-04-08
      • 2017-06-18
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多