Ultra-fast jobs display: backend returns first 40 jobs instantly, frontend renders immediately, full set updates when ready
This commit is contained in:
+27
-19
@@ -413,25 +413,33 @@
|
||||
startProgress();
|
||||
clearJobsCache('Loading…');
|
||||
const startTime = performance.now();
|
||||
try{
|
||||
// All job data should be fetched from backend/Valkey cache
|
||||
const url = `/api/jobs-all`;
|
||||
const res = await fetchNoCache(url);
|
||||
if(!res.ok) throw new Error(`Fetch failed: ${res.status}`);
|
||||
const data = await res.json();
|
||||
const items = data.items || [];
|
||||
jobsCache.push(...items);
|
||||
const loadTime = Math.round(performance.now() - startTime);
|
||||
console.log(`✓ Loaded ${items.length} jobs from API in ${loadTime}ms`);
|
||||
|
||||
// Show results immediately
|
||||
progressBar.style.width='95%';
|
||||
const renderStart = performance.now();
|
||||
applyFiltersAndRender();
|
||||
const renderTime = Math.round(performance.now() - startTime);
|
||||
console.log(`✓ Rendered jobs in ${renderTime}ms (Total: ${Math.round(performance.now() - startTime)}ms)`);
|
||||
finishProgress();
|
||||
}catch(err){ finishProgress(); alert('Failed to fetch jobs: '+err.message); console.error(err);}
|
||||
let pollCount = 0;
|
||||
async function pollJobs(){
|
||||
try{
|
||||
const url = `/api/jobs-all`;
|
||||
const res = await fetchNoCache(url);
|
||||
if(!res.ok) throw new Error(`Fetch failed: ${res.status}`);
|
||||
const data = await res.json();
|
||||
const items = data.items || [];
|
||||
if (pollCount === 0 || jobsCache.length === 0) {
|
||||
jobsCache.length = 0;
|
||||
jobsCache.push(...items);
|
||||
progressBar.style.width='95%';
|
||||
applyFiltersAndRender();
|
||||
}
|
||||
if (data.partial) {
|
||||
// If partial, poll again after short delay
|
||||
pollCount++;
|
||||
if (pollCount < 10) setTimeout(pollJobs, 600);
|
||||
else finishProgress();
|
||||
} else {
|
||||
finishProgress();
|
||||
const loadTime = Math.round(performance.now() - startTime);
|
||||
console.log(`✓ Loaded ${items.length} jobs from API in ${loadTime}ms`);
|
||||
}
|
||||
}catch(err){ finishProgress(); alert('Failed to fetch jobs: '+err.message); console.error(err); }
|
||||
}
|
||||
pollJobs();
|
||||
}
|
||||
|
||||
function renderInitialBatch(jobs){
|
||||
|
||||
Reference in New Issue
Block a user