From 5e3c49d609b8abef1ce1f8dd980000b678121c42 Mon Sep 17 00:00:00 2001 From: qiuxiang <394405259@qq.com> Date: Fri, 18 Sep 2026 14:36:23 +0800 Subject: [PATCH] =?UTF-8?q?perf:=20=E4=BA=AC=E4=B8=9C=E6=97=A5=E8=B4=A6?= =?UTF-8?q?=E5=8D=95=E6=B7=B1=E9=A1=B5=E5=85=88=E5=88=86=E9=A1=B5=E7=B4=A2?= =?UTF-8?q?=E5=BC=95=E5=86=8D=E8=AF=BB=E5=8F=96=E6=98=8E=E7=BB=86?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../Repositories/JdDailyBillRepository.php | 11 +++++++++-- 1 file changed, 9 insertions(+), 2 deletions(-) diff --git a/modules/EcommerceFinance/Repositories/JdDailyBillRepository.php b/modules/EcommerceFinance/Repositories/JdDailyBillRepository.php index d23d4982..388d11bc 100644 --- a/modules/EcommerceFinance/Repositories/JdDailyBillRepository.php +++ b/modules/EcommerceFinance/Repositories/JdDailyBillRepository.php @@ -18,9 +18,16 @@ class JdDailyBillRepository $total = (int) $summary->count; $page = max(1, $page); $perPage = min(100, max(1, $perPage)); - $rows = $this->ordered($query, $sort, $direction)->forPage($page, $perPage)->pluck('row_data'); + // Skip deep pages using narrow indexed keys, then load JSON only for the visible rows. + $keys = $this->ordered($query, $sort, $direction)->forPage($page, $perPage)->get(['generation', 'record_code']); + $rows = []; + foreach ($keys->groupBy('generation') as $generation => $group) { + $records = $this->db()->table('jd_daily_bill_rows')->where('generation', $generation) + ->whereIn('record_code', $group->pluck('record_code')->all())->get(['record_code', 'row_data']); + foreach ($records as $record) $rows[$generation . ':' . $record->record_code] = json_decode($record->row_data, true, 512, JSON_THROW_ON_ERROR); + } return [ - 'data' => $rows->map(fn ($r) => json_decode($r, true, 512, JSON_THROW_ON_ERROR))->all(), + 'data' => $keys->map(fn ($key) => $rows[$key->generation . ':' . $key->record_code])->all(), 'total' => $total, 'current_page' => $page, 'last_page' => max(1, (int) ceil($total / $perPage)), 'per_page' => $perPage, 'summary' => ['count' => $total, 'income' => round((float) $summary->income, 2), 'expense' => round((float) $summary->expense, 2), 'balance' => round((float) $summary->income - (float) $summary->expense, 2)], -- 2.47.2