Skip to content

Commit

Permalink
Merge branch 'dev'
Browse files Browse the repository at this point in the history
  • Loading branch information
arildm committed Sep 20, 2023
2 parents 4749dd9 + 7b064aa commit 56401f7
Show file tree
Hide file tree
Showing 3 changed files with 13 additions and 17 deletions.
1 change: 1 addition & 0 deletions src/api/backend.composable.js
Original file line number Diff line number Diff line change
Expand Up @@ -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`);

Expand Down
26 changes: 9 additions & 17 deletions src/corpora/corpora.composable.js
Original file line number Diff line number Diff line change
Expand Up @@ -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;
}

Expand Down
3 changes: 3 additions & 0 deletions src/corpus/corpus.composable.js
Original file line number Diff line number Diff line change
Expand Up @@ -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 = {};
Expand All @@ -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) {
Expand All @@ -28,6 +30,7 @@ export default function useCorpus(corpusId) {
await Promise.all([
loadConfig(), //
loadExports(),
loadJob(),
loadSources(),
]);
isCorpusFresh[corpusId] = true;
Expand Down

0 comments on commit 56401f7

Please sign in to comment.