diff --git a/src/api/backend.composable.js b/src/api/backend.composable.js index d410c13..7684ca5 100644 --- a/src/api/backend.composable.js +++ b/src/api/backend.composable.js @@ -76,6 +76,7 @@ export default function useMinkBackend() { const loadJob = (corpusId) => spin(api.checkStatus(corpusId), t("job.loading"), `corpus/${corpusId}/job`); + /** Load job status data for those corpora that have any job info. */ const loadJobs = () => spin(api.checkStatusAll(), t("job.loading"), `corpora`); diff --git a/src/corpora/corpora.composable.js b/src/corpora/corpora.composable.js index 243d93e..7f7edfb 100644 --- a/src/corpora/corpora.composable.js +++ b/src/corpora/corpora.composable.js @@ -13,30 +13,22 @@ export default function useCorpora() { const { alertError } = useMessenger(); const mink = useMinkBackend(); + async function doLoadCorpora() { + const corpusIds = await mink.loadCorpora().catch(alertError); + corpusStore.setCorpusIds(corpusIds); + } + async function loadCorpora(force = false) { + // Skip if already loaded. if (isCorporaFresh && !force) return; // Store the pending request in module scope, so simultaneous calls will await the same promise. - if (!loadPromise) { - loadPromise = mink - .loadCorpora() - .catch(alertError) - .then((corpora) => corpusStore.setCorpusIds(corpora)); - - // This request can take some time, so better not await it. - mink - .loadJobs() - .catch(alertError) - .then((jobs) => - jobs.forEach((job) => { - corpusStore.corpora[job.corpus_id].status = job; - }) - ); - } - + if (!loadPromise) loadPromise = doLoadCorpora(); await loadPromise; + // Unset the promise slot to allow any future, forced calls. loadPromise = null; + // Register that data has been loaded to skip future, unforced calls. isCorporaFresh = true; } diff --git a/src/corpus/corpus.composable.js b/src/corpus/corpus.composable.js index a987d35..8bf7dca 100644 --- a/src/corpus/corpus.composable.js +++ b/src/corpus/corpus.composable.js @@ -6,6 +6,7 @@ import useCorpora from "@/corpora/corpora.composable"; import useConfig from "./config/config.composable"; import useExports from "./exports/exports.composable"; import useSources from "./sources/sources.composable"; +import useJob from "./job/job.composable"; /** Let data be refreshed initially, but skip subsequent load calls. */ const isCorpusFresh = {}; @@ -18,6 +19,7 @@ export default function useCorpus(corpusId) { const { alertError } = useMessenger(); const { loadConfig } = useConfig(corpusId); const { loadExports } = useExports(corpusId); + const { loadJob } = useJob(corpusId); const { loadSources } = useSources(corpusId); async function loadCorpus(force = false) { @@ -28,6 +30,7 @@ export default function useCorpus(corpusId) { await Promise.all([ loadConfig(), // loadExports(), + loadJob(), loadSources(), ]); isCorpusFresh[corpusId] = true;