有什么方法可以使Laravel操作集合如此之快? 说明:

问题描述

  • Laravel版本:8.0
  • Nova版本:3.14
  • PHP版本:7.4
  • 数据库驱动程序和版本:5.7(MYSQL)

说明:

我有一个带有Laravel nova的清单应用程序。在该应用程序上,我正在使用mpdf library以pdf格式下载任何资源。有些时候,我们需要pdf上的数千条记录。但是,如果我在过滤掉索引布局之后检查了数千条记录,那么仍然需要花费大量时间才能将这些集合加载到Laravel nova操作中。

有什么解决方案可以使动作集合超快?

还是通过任何方式获取请求过滤器并进行自定义查询以获取集合?

这是我的操作代码:

/**
     * The number of models that should be included in each chunk.
     *
     * @var int
     */
    public static $chunkCount = 200000000;

    /**
     * Perform the action on the given models.
     *
     * @param  \Laravel\Nova\Fields\ActionFields  $fields
     * @param  \Illuminate\Support\Collection  $models
     * @return mixed
     */
    public function handle(ActionFields $fields,Collection $models)
    {
        if($models->count() > 1000)
        {
            return Action::danger('Maximum rows exceeded.');
        }
        $filename = "assets_".time().".pdf";
        $subtitle = $fields->subtitle;

        ini_set("pcre.backtrack_limit","10000000000");
        $pdf = \PDF::loadView('pdf.pages.assets',compact('models','subtitle'),[],[
            'mode' => 'utf-8',]);
        $pdf->save(Storage::path($filename));

        return Action::redirect( route('dump-download',compact('filename')) );
    }

    /**
     * Get the fields available on the action.
     *
     * @return array
     */
    public function fields()
    {
        return [
            Text::make('Subtitle','subtitle')
                ->rules('nullable','string','max:100')
        ];
    }

解决方法

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

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

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