sasdsad
This commit is contained in:
@@ -802,7 +802,7 @@ final class Router
|
||||
{
|
||||
$settings = $settingsOverride ?? $this->settings($projectKey);
|
||||
$rows = $this->repository()->listMeasurements($projectKey, 500);
|
||||
$rows = $this->ensureMeasurementFxReferences($projectKey, $rows);
|
||||
$rows = $this->ensureMeasurementFxReferences($projectKey, $rows, $settings);
|
||||
return $this->analytics()->enrichMeasurements($rows, $settings);
|
||||
}
|
||||
|
||||
@@ -1583,11 +1583,14 @@ final class Router
|
||||
return $result;
|
||||
}
|
||||
|
||||
private function resolveMeasurementFxFetchId(string $projectKey, array $payload, bool $allowRefresh): ?int
|
||||
private function resolveMeasurementFxFetchId(string $projectKey, array $payload, bool $allowRefresh, ?float $maxAgeHoursOverride = null): ?int
|
||||
{
|
||||
$measuredAt = trim((string) ($payload['measured_at'] ?? ''));
|
||||
$settings = $this->settings($projectKey);
|
||||
$maxAgeHours = is_numeric($settings['fx_max_age_hours'] ?? null) ? (float) $settings['fx_max_age_hours'] : 3.0;
|
||||
$maxAgeHours = $maxAgeHoursOverride;
|
||||
if ($maxAgeHours === null) {
|
||||
$settings = $this->settings($projectKey);
|
||||
$maxAgeHours = is_numeric($settings['fx_max_age_hours'] ?? null) ? (float) $settings['fx_max_age_hours'] : 3.0;
|
||||
}
|
||||
|
||||
if ($allowRefresh && $measuredAt !== '' && $this->isRecentTimestamp($measuredAt, $maxAgeHours)) {
|
||||
$fresh = $this->fx()->ensureFreshLatestRates($maxAgeHours, 'USD');
|
||||
@@ -1618,8 +1621,10 @@ final class Router
|
||||
return null;
|
||||
}
|
||||
|
||||
private function ensureMeasurementFxReferences(string $projectKey, array $rows): array
|
||||
private function ensureMeasurementFxReferences(string $projectKey, array $rows, ?array $settings = null): array
|
||||
{
|
||||
$maxAgeHours = is_numeric($settings['fx_max_age_hours'] ?? null) ? (float) $settings['fx_max_age_hours'] : 3.0;
|
||||
$resolvedByTimestamp = [];
|
||||
$resolved = [];
|
||||
foreach ($rows as $row) {
|
||||
if (!is_array($row)) {
|
||||
@@ -1628,9 +1633,18 @@ final class Router
|
||||
|
||||
$fetchId = is_numeric($row['fx_fetch_id'] ?? null) ? (int) $row['fx_fetch_id'] : 0;
|
||||
if ($fetchId <= 0) {
|
||||
$resolvedFetchId = $this->resolveMeasurementFxFetchId($projectKey, $row, false);
|
||||
$measuredAt = trim((string) ($row['measured_at'] ?? ''));
|
||||
if ($measuredAt !== '' && array_key_exists($measuredAt, $resolvedByTimestamp)) {
|
||||
$resolvedFetchId = $resolvedByTimestamp[$measuredAt];
|
||||
} else {
|
||||
$resolvedFetchId = $this->resolveMeasurementFxFetchId($projectKey, $row, false, $maxAgeHours);
|
||||
if ($measuredAt !== '') {
|
||||
$resolvedByTimestamp[$measuredAt] = $resolvedFetchId;
|
||||
}
|
||||
}
|
||||
|
||||
if ($resolvedFetchId !== null) {
|
||||
$row = $this->repository()->setMeasurementFxFetchId($projectKey, (int) ($row['id'] ?? 0), $resolvedFetchId) ?? array_merge($row, ['fx_fetch_id' => $resolvedFetchId]);
|
||||
$row['fx_fetch_id'] = $resolvedFetchId;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user