CaiWuXiTong/modules/EcommerceFinance/Services/UpstreamReadOnlyQueryFactory.php
aaron 93a27725b6 feat(财务台账): 接入 AI 轻量视图并改为分批增量快照 (#411)
本地验证:7 天和 30 天增量合并后,12,037 笔明细、收入 184,308,335.23、支出 155,917,513.13 保持不变。
2026-10-21 10:37:59 +08:00

33 lines
971 B
PHP

<?php
namespace Modules\EcommerceFinance\Services;
class UpstreamReadOnlyQueryFactory
{
/** @var array<string,UpstreamReadOnlyQuery> */
private array $instances = [];
/** @var array<string,UpstreamReadOnlyQuery> */
private array $timedInstances = [];
public function __construct(private readonly UpstreamSourceRegistry $sources)
{
}
public function forSource(string $source): UpstreamReadOnlyQuery
{
$key = $this->sources->definition($source)['key'];
return $this->instances[$key] ??= new UpstreamReadOnlyQuery($key);
}
public function forSourceWithTimeout(string $source, int $timeoutSeconds): UpstreamReadOnlyQuery
{
$key = $this->sources->definition($source)['key'];
$timeoutSeconds = max(1, min($timeoutSeconds, 120));
$cacheKey = $key . '@' . $timeoutSeconds;
return $this->timedInstances[$cacheKey] ??= new UpstreamReadOnlyQuery($key, $timeoutSeconds);
}
}