Fix: robust token/session handling, no client-side job data caching, improved reauth flow
This commit is contained in:
+2
-24
@@ -414,35 +414,13 @@
|
|||||||
clearJobsCache('Loading…');
|
clearJobsCache('Loading…');
|
||||||
const startTime = performance.now();
|
const startTime = performance.now();
|
||||||
try{
|
try{
|
||||||
// Check client-side cache first (sessionStorage)
|
// All job data should be fetched from backend/Valkey cache
|
||||||
const cachedData = sessionStorage.getItem('jobsCache');
|
|
||||||
const cacheTime = sessionStorage.getItem('jobsCacheTime');
|
|
||||||
const cacheAge = cacheTime ? Date.now() - parseInt(cacheTime) : Infinity;
|
|
||||||
|
|
||||||
// Use client cache if less than 5 minutes old
|
|
||||||
if (cachedData && cacheAge < 300000) {
|
|
||||||
const data = JSON.parse(cachedData);
|
|
||||||
jobsCache.push(...data);
|
|
||||||
const loadTime = Math.round(performance.now() - startTime);
|
|
||||||
console.log(`✓ Loaded ${data.length} jobs from CLIENT CACHE in ${loadTime}ms`);
|
|
||||||
progressBar.style.width='95%';
|
|
||||||
applyFiltersAndRender();
|
|
||||||
finishProgress();
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
|
|
||||||
// Use single cached endpoint that returns all jobs at once
|
|
||||||
const url = `/api/jobs-all`;
|
const url = `/api/jobs-all`;
|
||||||
const res = await fetchNoCache(url);
|
const res = await fetchNoCache(url);
|
||||||
if(!res.ok) throw new Error(`Fetch failed: ${res.status}`);
|
if(!res.ok) throw new Error(`Fetch failed: ${res.status}`);
|
||||||
const data = await res.json();
|
const data = await res.json();
|
||||||
const items = data.items || [];
|
const items = data.items || [];
|
||||||
jobsCache.push(...items);
|
jobsCache.push(...items);
|
||||||
|
|
||||||
// Store in client-side cache
|
|
||||||
sessionStorage.setItem('jobsCache', JSON.stringify(items));
|
|
||||||
sessionStorage.setItem('jobsCacheTime', Date.now().toString());
|
|
||||||
|
|
||||||
const loadTime = Math.round(performance.now() - startTime);
|
const loadTime = Math.round(performance.now() - startTime);
|
||||||
console.log(`✓ Loaded ${items.length} jobs from API in ${loadTime}ms`);
|
console.log(`✓ Loaded ${items.length} jobs from API in ${loadTime}ms`);
|
||||||
|
|
||||||
@@ -450,7 +428,7 @@
|
|||||||
progressBar.style.width='95%';
|
progressBar.style.width='95%';
|
||||||
const renderStart = performance.now();
|
const renderStart = performance.now();
|
||||||
applyFiltersAndRender();
|
applyFiltersAndRender();
|
||||||
const renderTime = Math.round(performance.now() - renderStart);
|
const renderTime = Math.round(performance.now() - startTime);
|
||||||
console.log(`✓ Rendered jobs in ${renderTime}ms (Total: ${Math.round(performance.now() - startTime)}ms)`);
|
console.log(`✓ Rendered jobs in ${renderTime}ms (Total: ${Math.round(performance.now() - startTime)}ms)`);
|
||||||
finishProgress();
|
finishProgress();
|
||||||
}catch(err){ finishProgress(); alert('Failed to fetch jobs: '+err.message); console.error(err);}
|
}catch(err){ finishProgress(); alert('Failed to fetch jobs: '+err.message); console.error(err);}
|
||||||
|
|||||||
Reference in New Issue
Block a user