运费对账:全量汇总缓存 1 小时,避免每 15 分钟重跑两分钟的重查询
无筛选的全量汇总约 110~200 秒,按原来的 900 秒缓存会让常看这个页面的人 反复等两分钟;带筛选的汇总走索引很快,保持 15 分钟。
This commit is contained in:
parent
1a024c2b26
commit
5b95b655bb
@ -218,9 +218,10 @@ class CourierFreightReconciliationMirrorRepository
|
||||
$previousSettings = [];
|
||||
try {
|
||||
if (is_array($cached = Cache::get($key))) return $cached;
|
||||
$unfiltered = array_filter($filters, static fn ($value): bool => trim((string) $value) !== '') === [];
|
||||
if ($this->connection->getDriverName() === 'mysql') {
|
||||
$settings = ['max_statement_time' => 300];
|
||||
if (array_filter($filters, static fn ($value): bool => trim((string) $value) !== '') === []) {
|
||||
if ($unfiltered) {
|
||||
$settings += [
|
||||
'optimizer_switch' => 'derived_merge=off,derived_with_keys=off',
|
||||
'join_cache_level' => 8,
|
||||
@ -241,7 +242,9 @@ class CourierFreightReconciliationMirrorRepository
|
||||
'COUNT(d.id) AS aggregate_count, COALESCE(SUM(o.freight), 0) AS freight',
|
||||
)->first();
|
||||
$summary = ['count' => (int) $row->aggregate_count, 'freight' => (float) $row->freight, 'computed_at' => $asOf];
|
||||
Cache::put($key, $summary, 900);
|
||||
// 全量(无筛选)汇总要跑两分钟左右,缓存久一点,避免频繁重算;
|
||||
// 带筛选的汇总走索引,很快,保持原来的 15 分钟。
|
||||
Cache::put($key, $summary, $unfiltered ? 3600 : 900);
|
||||
return $summary;
|
||||
} finally {
|
||||
try {
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user