mirror of
https://github.com/galaxyproject/galaxy.git
synced 2026-10-31 10:32:11 +08:00
To avoid multiple similar queries to the backend since fileSources are rather static.
30 lines
1.1 KiB
TypeScript
30 lines
1.1 KiB
TypeScript
import { defineStore } from "pinia";
|
|
import { ref } from "vue";
|
|
|
|
import { type BrowsableFilesSourcePlugin, fetchFileSources, type FilterFileSourcesOptions } from "@/api/remoteFiles";
|
|
|
|
export const useFileSourcesStore = defineStore("fileSourcesStore", () => {
|
|
const cachedFileSources = ref<{
|
|
[key: string]: BrowsableFilesSourcePlugin[] | Promise<BrowsableFilesSourcePlugin[]>;
|
|
}>({});
|
|
|
|
async function getFileSources(options: FilterFileSourcesOptions = {}): Promise<BrowsableFilesSourcePlugin[]> {
|
|
const cacheKey = getCacheKey(options);
|
|
if (cachedFileSources.value[cacheKey] === undefined) {
|
|
cachedFileSources.value[cacheKey] = fetchFileSources(options);
|
|
}
|
|
if (cachedFileSources.value[cacheKey] instanceof Promise) {
|
|
cachedFileSources.value[cacheKey] = await cachedFileSources.value[cacheKey]!;
|
|
}
|
|
return cachedFileSources.value[cacheKey]!;
|
|
}
|
|
|
|
function getCacheKey(options: FilterFileSourcesOptions) {
|
|
return JSON.stringify(options);
|
|
}
|
|
|
|
return {
|
|
getFileSources,
|
|
};
|
|
});
|