Every analytics tool wants a subscription. And your data. I built Twiligent instead. YouTube stats. Instagram stats. One dashboard. Runs locally on your machine.
refactor(overview): make overview load failures an explicit fallback
spacesdrive4a5f70eeeae8
diff --git a/docs/architecture/backend/CACHING.md b/docs/architecture/backend/CACHING.mdindex 9d029d7..1e073c7 100644--- a/docs/architecture/backend/CACHING.md+++ b/docs/architecture/backend/CACHING.md@@ -40,7 +40,7 @@ export async function getVideosCache(redis, userId, accountId) {## Overview warming-`GET /api/overview` returns `{ cacheWarmed, syncing }` per account. When an account has no cache entry it starts a background fetch with `waitUntil` (YouTube, Instagram and Reddit) and returns `syncing: true` only if that fetch actually started. Without Redis, an API key, a token or a cookie it returns `syncing: false`, so the client never waits on something that cannot load. The client re-polls at 4, 8 and 16 seconds while any account is syncing, then stops.+`GET /api/overview` returns `{ cacheWarmed, syncing }` per account. When an account has no cache entry it starts a background fetch with `waitUntil` (YouTube, Instagram and Reddit) and returns `syncing: true` only if that fetch actually started. Without Redis, an API key, a token or a cookie it returns `syncing: false`, so the client never waits on something that cannot load. While any account is syncing the client polls again up to three times. Each poll waits 4, 8 and then 16 seconds after the previous response (about 4, 12 and 28 seconds after the first load), then polling stops.## Cache Usage in Routesdiff --git a/docs/architecture/data-flows/ANALYTICS.md b/docs/architecture/data-flows/ANALYTICS.mdindex 0850f32..848bfb4 100644--- a/docs/architecture/data-flows/ANALYTICS.md+++ b/docs/architecture/data-flows/ANALYTICS.md@@ -220,8 +220,9 @@ Overview.jsx uses accounts from AppContext (data loaded by useOverviewData.js)The Overview does not fetch fresh per-account analytics. It combines account metadata alreadyin `AppContext.accounts` with whatever each account's Redis analytics cache holds. When anyaccount's cache is cold the backend fires a background warm-up and returns `cacheWarmed: false`-with `syncing: true`. While any account is syncing, the page fetches the overview again after 4,-8 and 16 seconds, then stops so the syncing label never hangs.+with `syncing: true`. While any account is syncing, the page fetches the overview again up to three times. The polls+are chained: each waits 4, 8 and then 16 seconds after the previous response, so they land about+4, 12 and 28 seconds after the first load. Then polling stops so the syncing label never hangs.### Metric definitionsdiff --git a/frontend/src/features/analytics/overview/useOverviewData.js b/frontend/src/features/analytics/overview/useOverviewData.jsindex 3be69d9..aa131be 100644--- a/frontend/src/features/analytics/overview/useOverviewData.js+++ b/frontend/src/features/analytics/overview/useOverviewData.js@@ -3,33 +3,43 @@ import { api } from '../../../services/api';const SYNC_POLL_DELAYS = [4000, 8000, 16000];+async function fetchOverview() {+ try {+ const data = await api.getOverview();+ return data && !data.error ? data : null;+ } catch {+ // a failed load keeps the previous overview; the next poll or visit tries again+ return null;+ }+}+export function useOverviewData(accounts) {const [overviewData, setOverviewData] = useState({ tracked: [], analyticsCache: {} });const [overviewLoading, setOverviewLoading] = useState(true);const [syncPolls, setSyncPolls] = useState(0);useEffect(() => {- api.getOverview()- .then(data => {- if (data && !data.error) setOverviewData(data);- })- .catch(() => {})- .finally(() => setOverviewLoading(false));+ const loadOverview = async () => {+ const data = await fetchOverview();+ if (data) setOverviewData(data);+ setOverviewLoading(false);+ };+ loadOverview();}, []);- // the backend marks accounts it is still fetching; poll with backoff and stop so the label never hangs+ // poll with backoff while syncing, then stop so the label never hangsconst isSyncing = !overviewLoading && syncPolls < SYNC_POLL_DELAYS.length && accounts.some(account => {return overviewData.analyticsCache[account.id]?.syncing === true;});useEffect(() => {if (!isSyncing) return undefined;- const timer = setTimeout(() => {- api.getOverview()- .then(data => { if (data && !data.error) setOverviewData(data); })- .catch(() => {})- .finally(() => setSyncPolls(polls => polls + 1));- }, SYNC_POLL_DELAYS[syncPolls]);+ const pollOverview = async () => {+ const data = await fetchOverview();+ if (data) setOverviewData(data);+ setSyncPolls(polls => polls + 1);+ };+ const timer = setTimeout(pollOverview, SYNC_POLL_DELAYS[syncPolls]);return () => clearTimeout(timer);}, [isSyncing, syncPolls]);diff --git a/frontend/src/hooks/use-cloudinary-config.js b/frontend/src/hooks/use-cloudinary-config.jsindex 3f10d6e..7aa963a 100644--- a/frontend/src/hooks/use-cloudinary-config.js+++ b/frontend/src/hooks/use-cloudinary-config.js@@ -16,9 +16,11 @@ export function useCloudinaryConfig(reloadKey) {const [config, setConfig] = useState(null);useEffect(() => {- fetchCloudinaryConfig().then(nextConfig => {+ const loadConfig = async () => {+ const nextConfig = await fetchCloudinaryConfig();if (nextConfig) setConfig(nextConfig);- });+ };+ loadConfig();}, [reloadKey]);return config;