fix(settings): drop program-settings last-good cache and prefer montzar
Stale Redis overlay and SMS-origin-first fetch kept feature flags like customer_special_pricing false after SuperAdmin turned them on. Always fetch live and try adm.montzar.ir first. Co-authored-by: Cursor <cursoragent@cursor.com>
This commit is contained in:
@@ -22,8 +22,21 @@ class SuperAdminProgramSettingsClient
|
||||
|
||||
public const RETRY_ROUNDS = 3;
|
||||
|
||||
/** @var array{channel?: string, origin?: string, domain?: string}|null */
|
||||
private ?array $lastFetchMeta = null;
|
||||
|
||||
/**
|
||||
* @return array{channel?: string, origin?: string, domain?: string}
|
||||
*/
|
||||
public function lastFetchMeta(): array
|
||||
{
|
||||
return $this->lastFetchMeta ?? [];
|
||||
}
|
||||
|
||||
public function fetchItems(): ?array
|
||||
{
|
||||
$this->lastFetchMeta = null;
|
||||
|
||||
$public = $this->fetchPublic();
|
||||
if ($public !== null) {
|
||||
return $public;
|
||||
@@ -68,7 +81,12 @@ class SuperAdminProgramSettingsClient
|
||||
}
|
||||
|
||||
$items = $this->extractItems($response->json());
|
||||
if ($items !== null) {
|
||||
if ($this->hasSettingRows($items)) {
|
||||
$this->lastFetchMeta = [
|
||||
'channel' => 'remote',
|
||||
'origin' => $origin,
|
||||
];
|
||||
|
||||
return $items;
|
||||
}
|
||||
} catch (\Throwable $e) {
|
||||
@@ -96,16 +114,29 @@ class SuperAdminProgramSettingsClient
|
||||
foreach ($this->attemptOrigins() as $origin) {
|
||||
try {
|
||||
$response = Http::acceptJson()
|
||||
->withHeaders(['Cache-Control' => 'no-store'])
|
||||
->withHeaders([
|
||||
'Cache-Control' => 'no-store',
|
||||
'Pragma' => 'no-cache',
|
||||
])
|
||||
->withOptions(['http_errors' => false])
|
||||
->timeout(6)
|
||||
->get($origin.self::PUBLIC_PATH, ['domain' => $domain]);
|
||||
->get($origin.self::PUBLIC_PATH, [
|
||||
'domain' => $domain,
|
||||
'_ts' => (string) time(),
|
||||
]);
|
||||
|
||||
if (! $response->successful() || ! $this->isJsonResponse($response)) {
|
||||
continue;
|
||||
}
|
||||
|
||||
$items = $this->extractItems($response->json());
|
||||
if ($items !== null) {
|
||||
if ($this->hasSettingRows($items)) {
|
||||
$this->lastFetchMeta = [
|
||||
'channel' => 'public',
|
||||
'origin' => $origin,
|
||||
'domain' => $domain,
|
||||
];
|
||||
|
||||
return $items;
|
||||
}
|
||||
} catch (\Throwable $e) {
|
||||
@@ -137,6 +168,9 @@ class SuperAdminProgramSettingsClient
|
||||
}
|
||||
|
||||
/**
|
||||
* اول montzar (منبع اصلی)، بعد origin/SMS صریح، بعد failover.
|
||||
* قبلاً SMS اول بود و اگر رپلیکای کهنه جواب ۲۰۰ میداد، montzar هیچوقت خوانده نمیشد.
|
||||
*
|
||||
* @return list<string>
|
||||
*/
|
||||
private function origins(): array
|
||||
@@ -162,7 +196,16 @@ class SuperAdminProgramSettingsClient
|
||||
}
|
||||
}
|
||||
|
||||
return array_values(array_unique(array_merge($extra, $defaults)));
|
||||
// montzar اول؛ extra فقط اگر هنوز در لیست نیست به انتها اضافه میشود
|
||||
return array_values(array_unique(array_merge($defaults, $extra)));
|
||||
}
|
||||
|
||||
/**
|
||||
* @param array<int, array<string, mixed>>|null $items
|
||||
*/
|
||||
private function hasSettingRows(?array $items): bool
|
||||
{
|
||||
return is_array($items) && $items !== [];
|
||||
}
|
||||
|
||||
private function isJsonResponse($response): bool
|
||||
|
||||
Reference in New Issue
Block a user