Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[DUOS-2853][risk=no] Cache doid responses in local storage #2432

Merged
merged 1 commit into from
Jan 11, 2024
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
20 changes: 14 additions & 6 deletions src/libs/ontologyService.js
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
import axios from 'axios';
import { Notifications } from './utils';
import { getOntologyUrl } from './ajax';
import {Notifications} from './utils';
import {getOntologyUrl} from './ajax';
import {Storage as storage} from '../libs/storage';


export const OntologyService = {
Expand All @@ -10,10 +11,17 @@ export const OntologyService = {
}
const baseURL = await getOntologyUrl();
const params = {id: obolibraryURL};
try{
let resp = await axios.get(`${baseURL}/search`, {params});
return resp.data;
} catch(error) {
try {
const data = storage.getData(obolibraryURL);
if (data !== null) {
return JSON.parse(data);
} else {
const response = await axios.get(`${baseURL}/search`, {params});
const data = response.data;
storage.setData(obolibraryURL, JSON.stringify(data));
return data;
}
} catch (error) {
Notifications.showError('Error: Ontology Search Request failed');
}
},
Expand Down
Loading