From 99cf5eaef23db5ef36f86dbbbbad585f0937a6fa Mon Sep 17 00:00:00 2001 From: Lars Gebhardt-Kusche Date: Wed, 3 Jun 2026 00:43:33 +0200 Subject: [PATCH] adasd --- modules/mining-checker/assets/js/app.js | 25 +++++++++++++++---- modules/mining-checker/src/Api/Router.php | 13 ++++++---- .../src/Domain/AnalyticsService.php | 9 +++---- 3 files changed, 31 insertions(+), 16 deletions(-) diff --git a/modules/mining-checker/assets/js/app.js b/modules/mining-checker/assets/js/app.js index 5302a80..ebf61ce 100644 --- a/modules/mining-checker/assets/js/app.js +++ b/modules/mining-checker/assets/js/app.js @@ -5,7 +5,7 @@ } const h = React.createElement; - const { useEffect, useMemo, useState } = React; + const { useEffect, useMemo, useRef, useState } = React; const apiBase = root.dataset.apiBase || '/api/mining-checker/v1'; const initialProjectKey = root.dataset.defaultProjectKey || 'doge-main'; const initialActiveTab = String(root.dataset.activeView || 'overview').trim() || 'overview'; @@ -734,6 +734,7 @@ const [error, setError] = useState(''); const [message, setMessage] = useState(''); const [schemaStatus, setSchemaStatus] = useState(normalizeSchemaStatus(null)); + const bootstrapCacheRef = useRef(new Map()); const [initForm, setInitForm] = useState({ drop_existing: false }); const [sqlImportFile, setSqlImportFile] = useState(null); const [dbCheck, setDbCheck] = useState(null); @@ -1160,14 +1161,21 @@ } async function loadBootstrap(key) { - setLoading(true); + const cacheKey = `${key}:${activeTab || 'overview'}`; + const cachedPayload = bootstrapCacheRef.current.get(cacheKey) || null; + + setLoading(!cachedPayload); setError(''); - setPayload((previous) => previous || normalizeBootstrap(null, key)); + if (cachedPayload) { + setPayload(cachedPayload); + } else { + setPayload((previous) => previous || normalizeBootstrap(null, key)); + } let loadGuardTriggered = false; const loadGuard = window.setTimeout(() => { loadGuardTriggered = true; setLoading(false); - setPayload((previous) => previous || normalizeBootstrap(null, key)); + setPayload((previous) => previous || cachedPayload || normalizeBootstrap(null, key)); setError((previous) => previous || 'Bootstrap-Request haengt oder braucht zu lange.'); }, 12000); @@ -1181,6 +1189,7 @@ const params = new URLSearchParams({ view: activeTab || 'overview' }); const data = await request(`${apiBase}/projects/${encodeURIComponent(key)}/bootstrap?${params.toString()}`, { timeoutMs: 10000 }); const normalized = normalizeBootstrap(data, key); + bootstrapCacheRef.current.set(cacheKey, normalized); setPayload(normalized); setSettingsForm({ baseline_measured_at: normalized.settings.baseline_measured_at || '', @@ -1191,7 +1200,6 @@ setFxSelection(Array.isArray(normalized.settings.preferred_currencies) && normalized.settings.preferred_currencies.length ? normalized.settings.preferred_currencies : ['DOGE', 'USD', 'EUR']); - loadFxHistory(key); setTargetForm((previous) => ({ ...previous, currency: normalized.settings.currencies?.[0]?.code || previous.currency || 'EUR', @@ -1215,6 +1223,13 @@ loadBootstrap(projectKey); }, [projectKey, activeTab]); + useEffect(() => { + if (activeTab !== 'mining') { + return; + } + loadFxHistory(projectKey); + }, [activeTab, projectKey]); + useEffect(() => { syncMiningCheckerTabButtons(activeTab); diff --git a/modules/mining-checker/src/Api/Router.php b/modules/mining-checker/src/Api/Router.php index 7cba751..e3701b0 100644 --- a/modules/mining-checker/src/Api/Router.php +++ b/modules/mining-checker/src/Api/Router.php @@ -1234,9 +1234,13 @@ final class Router return []; } - $rows = in_array($view, ['overview', 'mining', 'measurements'], true) - ? $this->repository()->listRecentMeasurements($projectKey, self::BOOTSTRAP_MEASUREMENT_LIMIT) - : $this->repository()->listMeasurements($projectKey, self::BOOTSTRAP_MEASUREMENT_LIMIT); + if (in_array($view, ['overview', 'mining'], true)) { + $rows = $this->repository()->listRecentMeasurements($projectKey, self::BOOTSTRAP_MEASUREMENT_LIMIT); + } elseif ($view === 'measurements') { + $rows = $this->repository()->listRecentMeasurements($projectKey, 10); + } else { + $rows = $this->repository()->listMeasurements($projectKey, self::BOOTSTRAP_MEASUREMENT_LIMIT); + } if (in_array($view, ['overview', 'mining'], true)) { $rows = $this->filterMeasurementsToRecentWindow($rows, self::OVERVIEW_WINDOW_DAYS); @@ -1278,13 +1282,12 @@ final class Router private function bootstrapFxSnapshots(array $measurements, string $view): array { - if (!in_array($view, ['overview', 'mining', 'measurements'], true)) { + if (!in_array($view, ['overview', 'mining'], true)) { return []; } $limit = match ($view) { 'overview' => 1, - 'measurements' => 10, default => self::BOOTSTRAP_SNAPSHOT_LIMIT, }; diff --git a/modules/mining-checker/src/Domain/AnalyticsService.php b/modules/mining-checker/src/Domain/AnalyticsService.php index 8bdee6e..6e637cd 100644 --- a/modules/mining-checker/src/Domain/AnalyticsService.php +++ b/modules/mining-checker/src/Domain/AnalyticsService.php @@ -33,9 +33,7 @@ final class AnalyticsService $previous = null; $previousMeasuredTs = null; $previousIntervalRate = null; - $previousVisibleCoins = null; $previousCoinCurrency = null; - $previousCumulativePayouts = null; $result = []; $payoutIndex = 0; $payoutsByAsset = []; @@ -164,7 +162,7 @@ final class AnalyticsService $normalizedFlags = is_array($decoded) ? $decoded : [$normalizedFlags]; } - $result[] = array_merge($row, [ + $enrichedRow = array_merge($row, [ 'coins_total_visible' => $this->roundOrNull($visibleCoinsTotal, 6), 'coins_total_effective' => $this->roundOrNull($effectiveCoinsTotal, 6), 'coin_currency' => $coinCurrency, @@ -195,15 +193,14 @@ final class AnalyticsService 'measured_date' => substr((string) $row['measured_at'], 0, 10), 'ocr_flags' => is_array($normalizedFlags) ? $normalizedFlags : [], ]); + $result[] = $enrichedRow; if ($perHourInterval !== null) { $previousIntervalRate = $perHourInterval; } - $previous = $row; + $previous = $enrichedRow; $previousMeasuredTs = $measuredTs > 0 ? $measuredTs : null; - $previousVisibleCoins = $visibleCoinsTotal; $previousCoinCurrency = $coinCurrency; - $previousCumulativePayouts = $cumulativePayouts; } return $result;