Skip to content

Commit

Permalink
Use resource-info also for sources, #143
Browse files Browse the repository at this point in the history
  • Loading branch information
arildm committed Jan 2, 2024
1 parent 28763a3 commit 9550885
Show file tree
Hide file tree
Showing 5 changed files with 17 additions and 24 deletions.
2 changes: 1 addition & 1 deletion CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ As this project is a user-facing application, the places in the semantic version

### Changed

- Use new `resource-info` route, drop `check-status`
- Use new `resource-info` route, drop `check-status` and `list-sources`
- The local storage key is now tagged with a datestamp, and should be changed when the data shape of the state changes

## [1.0.5] (2023-11-28)
Expand Down
7 changes: 0 additions & 7 deletions src/api/api.js
Original file line number Diff line number Diff line change
Expand Up @@ -57,13 +57,6 @@ class MinkApi {
return response.data;
}

async listSources(corpusId) {
const response = await this.axios.get("list-sources", {
params: { corpus_id: corpusId },
});
return response.data.contents;
}

async downloadSourceFile(corpusId, filename, binary = false) {
const response = await this.axios.get("download-sources", {
params: { corpus_id: corpusId, file: filename, zip: false },
Expand Down
8 changes: 0 additions & 8 deletions src/api/backend.composable.js
Original file line number Diff line number Diff line change
Expand Up @@ -38,13 +38,6 @@ export default function useMinkBackend() {
`corpus/${corpusId}/config`
);

const loadSources = (corpusId) =>
spin(
api.listSources(corpusId),
t("source.list.loading"),
`corpus/${corpusId}/sources`
);

const downloadSource = (corpusId, filename, binary) =>
spin(
api.downloadSourceFile(corpusId, filename, binary),
Expand Down Expand Up @@ -135,7 +128,6 @@ export default function useMinkBackend() {
deleteCorpus,
loadConfig,
saveConfig,
loadSources,
downloadSource,
downloadPlaintext,
uploadSources,
Expand Down
20 changes: 14 additions & 6 deletions src/corpus/corpus.composable.js
Original file line number Diff line number Diff line change
Expand Up @@ -5,8 +5,6 @@ import useMessenger from "@/message/messenger.composable";
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 @@ -19,23 +17,33 @@ 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) {
// Make sure the corpus has an entry in the store.
await loadCorpora();
if (isCorpusFresh[corpusId] && !force) {
return;
}

// Load all essential info about the corpus.
await Promise.all([
loadConfig(), //
loadExports(),
loadJob(),
loadSources(),
loadResourceInfo(),
]);

// Remember to skip loading next time.
isCorpusFresh[corpusId] = true;
}

/** Load job status and source files in the same request. */
async function loadResourceInfo() {
const info = await mink.resourceInfo(corpusId).catch(alertError);
corpusStore.corpora[corpusId].name = info.resource.name;
corpusStore.corpora[corpusId].sources = info.resource.source_files;
corpusStore.corpora[corpusId].status = info.job;
}

async function deleteCorpus(corpusId_ = corpusId) {
// Delete corpus in the backend.
await mink.deleteCorpus(corpusId_).catch(alertError);
Expand Down
4 changes: 2 additions & 2 deletions src/corpus/sources/sources.composable.js
Original file line number Diff line number Diff line change
Expand Up @@ -13,8 +13,8 @@ export default function useSources(corpusId) {
const sources = computed(() => corpusStore.corpora[corpusId]?.sources || []);

async function loadSources(corpusId_ = corpusId) {
const sourcesFetched = await mink.loadSources(corpusId_).catch(alertError);
corpusStore.corpora[corpusId_].sources = sourcesFetched;
const info = await mink.resourceInfo(corpusId_).catch(alertError);
corpusStore.corpora[corpusId_].sources = info.resource.source_files;
}

async function downloadSource(source, binary) {
Expand Down

0 comments on commit 9550885

Please sign in to comment.