Skip to content

Commit

Permalink
Improve concept loading
Browse files Browse the repository at this point in the history
  • Loading branch information
stefandesu committed Dec 2, 2024
1 parent 3dec634 commit be5d920
Show file tree
Hide file tree
Showing 2 changed files with 7 additions and 6 deletions.
11 changes: 6 additions & 5 deletions src/client/store.js
Original file line number Diff line number Diff line change
Expand Up @@ -84,10 +84,10 @@ export async function getRegistryForScheme(scheme) {
return state.schemes.find(s => jskos.compare(s, scheme))?._registry
}

export async function getRegistryForUri(uri) {
export async function getRegistryForUri(uri, scheme) {
await schemeFetchPromise
// Find scheme where URI matches namespace
return await getRegistryForScheme(state.schemes.find(scheme => scheme.notationFromUri(uri)))
return await getRegistryForScheme(scheme || state.schemes.find(scheme => scheme.notationFromUri(uri)))
}

export function getConcept(concept) {
Expand Down Expand Up @@ -162,8 +162,8 @@ export function saveConceptsWithOptions(options) {
}

let properties
export async function loadConcept(uri) {
const registry = await getRegistryForUri(uri)
export async function loadConcept(uri, scheme) {
const registry = await getRegistryForUri(uri, scheme)
if (!registry) {
return null
}
Expand All @@ -178,7 +178,8 @@ export async function loadConcept(uri) {
return existing
}
console.time(`loadConcept ${uri}`)
const concept = (await registry.getConcepts({ concepts: [{ uri }], params: { properties } }))[0]
scheme = scheme ? { uri: scheme.uri, identifier: scheme.identifier } : null
const concept = (await registry.getConcepts({ concepts: [{ uri }], params: { properties }, scheme }))[0]
console.timeEnd(`loadConcept ${uri}`)
if (!concept) {
throw new Error(`Error loading concept ${uri}`)
Expand Down
2 changes: 1 addition & 1 deletion src/client/views/HomeView.vue
Original file line number Diff line number Diff line change
Expand Up @@ -47,8 +47,8 @@ watch(() => ([schemesAsConceptSchemes.value, route.query.uri]), async ([schemes,
}
// Fallback: Request data from backend about concept directly
try {
const concept = await loadConcept(uri)
const scheme = schemes.find(s => jskos.compare(s, concept?.inScheme?.[0]))
const concept = await loadConcept(uri, scheme)
if (concept && scheme) {
router.push(getRouterUrl({ concept, scheme }))
return
Expand Down

0 comments on commit be5d920

Please sign in to comment.