From 2bcb0567d82c33cd50ac032809424498b5898d40 Mon Sep 17 00:00:00 2001 From: Guillaume Bouvignies Date: Tue, 31 Oct 2023 11:29:07 +0100 Subject: [PATCH] fix: Load schedule statistics in background (#2530) --- .../(root)/(logged)/schedules/+page.svelte | 83 +++++++++++++------ 1 file changed, 56 insertions(+), 27 deletions(-) diff --git a/frontend/src/routes/(root)/(logged)/schedules/+page.svelte b/frontend/src/routes/(root)/(logged)/schedules/+page.svelte index fb93e1ea62..2fb90867c4 100644 --- a/frontend/src/routes/(root)/(logged)/schedules/+page.svelte +++ b/frontend/src/routes/(root)/(logged)/schedules/+page.svelte @@ -24,6 +24,7 @@ faTrash } from '@fortawesome/free-solid-svg-icons' import { Icon } from 'svelte-awesome' + import { Loader2 } from 'lucide-svelte' import { goto } from '$app/navigation' import { sendUserToast } from '$lib/toast' import SearchItems from '$lib/components/SearchItems.svelte' @@ -36,14 +37,34 @@ let schedules: ScheduleW[] = [] let shareModal: ShareModal let loading = true + let loadingSchedulesWithJobStats = true async function loadSchedules(): Promise { - schedules = (await ScheduleService.listSchedulesWithJobs({ workspace: $workspaceStore! })).map( - (x) => { - return { canWrite: canWrite(x.path, x.extra_perms!, $userStore), ...x } - } - ) + schedules = (await ScheduleService.listSchedules({ workspace: $workspaceStore! })).map((x) => { + return { canWrite: canWrite(x.path, x.extra_perms!, $userStore), ...x } + }) loading = false + // after the schedule core data has been loaded, load all the job stats + // TODO: we could potentially not reload the job stats on every call to loadSchedules, but for now it's + // simpler to always call it. Update if performance becomes an issue. + loadSchedulesWithJobStats() + } + + async function loadSchedulesWithJobStats(): Promise { + loadingSchedulesWithJobStats = true + let schedulesWithJobsByPath = new Map() + let schedulesWithJobsList = await ScheduleService.listSchedulesWithJobs({ + workspace: $workspaceStore! + }) + schedulesWithJobsList.map((x) => { + schedulesWithJobsByPath[x.path] = x + }) + for (let schedule of schedules) { + if (schedulesWithJobsByPath[schedule.path]) { + schedule.jobs = schedulesWithJobsByPath[schedule.path].jobs + } + } + loadingSchedulesWithJobStats = false } async function setScheduleEnabled(path: string, enabled: boolean): Promise { @@ -276,28 +297,36 @@
-
- {#if avg_s} -
Avg: {(avg_s / 1000).toFixed(2)}s
- {/if} - {#each jobs ?? [] as job} - {@const h = (avg_s ? job.duration_ms / avg_s : 1) * 7 + 3} - - -
-
- -
- -
- {/each} -
-
+ + Job stats loading... +
+ {:else} +
+ {#if avg_s} +
Avg: {(avg_s / 1000).toFixed(2)}s
+ {/if} + {#each jobs ?? [] as job} + {@const h = (avg_s ? job.duration_ms / avg_s : 1) * 7 + 3} + + +
+
+ +
+ +
+ {/each} +
+ {/if} +
edited by {edited_by}
the {displayDate(edited_at)}