CaiWuXiTong/app/Console/Commands/WarmOrderDataShopCandidates.php
renshen c4a976751d 修复订单售后页面一直转圈:店铺候选改成定时预热
上一次把店铺候选的完整计算放在 app()->terminating() 里,但服务器是 mod_php,
响应要等整个请求(含终止回调)结束才算完成,浏览器就一直转圈、侧边栏停在骨架屏。
线上实测:发布后第一个打开订单售后费用明细的人,页面会卡两分钟以上。

改成:页面只返回毫秒级的店铺目录兜底,完整候选(目录 ∪ 订单镜像店铺)由新增的
order-data:warm-shop-candidates 每小时预热一次,并在发布脚本的 cron 里注册。
2026-10-07 14:21:36 +08:00

31 lines
998 B
PHP

<?php
namespace App\Console\Commands;
use Illuminate\Console\Command;
use Illuminate\Support\Facades\Log;
use Modules\EcommerceFinance\Repositories\OrderDataMirrorRepository;
use Throwable;
class WarmOrderDataShopCandidates extends Command
{
protected $signature = 'order-data:warm-shop-candidates';
protected $description = '预热订单售后费用明细的店铺候选(要扫两张百万级订单宽表,不能放在页面请求里)';
public function handle(OrderDataMirrorRepository $orders): int
{
try {
$names = $orders->refreshShopNamesCache();
$this->info(sprintf('店铺候选已预热,共 %d 个店铺。', count($names)));
return self::SUCCESS;
} catch (Throwable $exception) {
Log::error('店铺候选预热失败。', ['exception' => $exception::class]);
$this->error('店铺候选预热失败:' . $exception->getMessage());
return self::FAILURE;
}
}
}