Skip to content

Commit

Permalink
Fix ontologies.get cache bug
Browse files Browse the repository at this point in the history
  • Loading branch information
srosset81 committed Dec 22, 2023
1 parent 4e052b3 commit 2bec049
Showing 1 changed file with 14 additions and 6 deletions.
20 changes: 14 additions & 6 deletions src/middleware/packages/ontologies/actions/get.js
Original file line number Diff line number Diff line change
Expand Up @@ -8,25 +8,33 @@ module.exports = {
cache: true,
async handler(ctx) {
let { prefix, namespace, uri } = ctx.params;
let ontology;

if (!prefix && !namespace && !uri) throw new Error('You must provide a prefix, namespace or uri parameter');

if (this.settings.persistRegistry) {
if (prefix) {
return await ctx.call('ontologies.registry.getByPrefix', { prefix });
ontology = await ctx.call('ontologies.registry.getByPrefix', { prefix });
} else if (namespace) {
return await ctx.call('ontologies.registry.getByNamespace', { namespace });
ontology = await ctx.call('ontologies.registry.getByNamespace', { namespace });
} else if (uri) {
const ontologies = await ctx.call('ontologies.registry.list');
return ontologies.find(o => uri.startsWith(o.namespace));
ontology = ontologies.find(o => uri.startsWith(o.namespace));
}
} else {
if (prefix) {
return this.ontologies[prefix];
ontology = this.ontologies[prefix] || false;
} else if (namespace) {
return Object.values(this.ontologies).find(o => o.namespace === namespace);
ontology = Object.values(this.ontologies).find(o => o.namespace === namespace);
} else if (uri) {
return Object.values(this.ontologies).find(o => uri.startsWith(o.namespace));
ontology = Object.values(this.ontologies).find(o => uri.startsWith(o.namespace));
}
}

// Must return null if no results, because the cache JsonSerializer cannot handle undefined values
// https://moleculer.services/docs/0.14/networking.html#JSON-serializer
if (ontology === undefined) ontology = null;

return ontology;
}
};

0 comments on commit 2bec049

Please sign in to comment.