fix channel price bug

This commit is contained in:
2026-07-07 18:21:36 +03:30
parent 10460beb5b
commit c9f363802e
2 changed files with 34 additions and 6 deletions
+14 -1
View File
@@ -141,7 +141,20 @@ class ReportController extends Controller
$payload['last_historical'] = app(ProductDisplayPriceService::class)->resolveHistoricalBasePrice();
app(ProductDisplayPriceService::class)->cacheLivePricePayload($payload);
if ($saveFullCache || request()->boolean('force_refresh')) {
$isFreshPrice = $saveFullCache || request()->boolean('force_refresh');
// ارسال قیمت به کانال فقط روی «لحظهٔ تغییر قیمت» = مسیر force_refresh (همان چیزی که سرورِ
// حساس به قیمت صدا می‌زند و مبنای برادکست SSE است) — نه هر pulling عادی که کش برمی‌گرداند.
// بعد از پاسخ اجرا می‌شود تا تاخیری برای فراخوان نباشد. در کنسول صدا نمی‌زنیم چون tick()
// خودش مستقیماً broadcastIfEligible را اجرا می‌کند و afterResponse در دیمن اجرا نمی‌شود.
// خودِ سرویس با price_channel_min_seconds و تشخیص تغییر قیمت گیت می‌کند.
if ($isFreshPrice && (int) ($payload['price'] ?? 0) > 0 && ! app()->runningInConsole()) {
dispatch(function () {
app(\App\Services\PriceChannelBroadcastService::class)->broadcastIfEligible();
})->afterResponse();
}
if ($isFreshPrice) {
$cache = app(LivePriceCacheService::class);
$cache->markTick();