Commit 3c6da172 authored by Laurent Wouters's avatar Laurent Wouters
Browse files

[fix] Use cache for RDF data store loading

parent 7315744c6f7e
......@@ -55,6 +55,7 @@ class LDBrowserData {
this.history = [init];
this.byResource = {};
this.byResource[observation.url] = init;
this.storeCache = {};
}
/**
* The history of resources
......@@ -127,27 +128,29 @@ function getBrowserLanguage(): application.Language {
function loadRdfStore(resource: ResourceData): Promise<$rdf.Formula> {
return new Promise(
(resolve: (store: $rdf.Formula) => void, reject: (reason: any) => void) => {
let sources = selectDataSources(resource);
if (sources.length == 0) {
reject("No available data.");
let cached = currentBrowser.storeCache[resource.observations.url];
if (cached != null && cached != undefined) {
resolve(cached);
return;
}
let sources = selectDataSources(resource);
let index = 0;
let tryNewSource = function() {
let tryNextSource = function() {
if (index >= sources.length) {
reject("No available data.");
return;
}
loadRdfStoreFrom(sources[index])
.then((store: $rdf.Formula) => {
currentBrowser.storeCache[resource.observations.url] = store;
resolve(store);
})
.catch((reason: any) => {
index++;
tryNewSource();
tryNextSource();
});
};
tryNewSource();
tryNextSource();
}
);
}
......@@ -159,11 +162,6 @@ function loadRdfStore(resource: ResourceData): Promise<$rdf.Formula> {
function loadRdfStoreFrom(source: DataSource): Promise<$rdf.Formula> {
return new Promise(
(resolve: (store: $rdf.Formula) => void, reject: (reason: any) => void) => {
let cached = currentBrowser.storeCache[source.url];
if (cached != null && cached != undefined) {
resolve(cached);
return;
}
fetchSource(source)
.then((value: RawContent) => {
let store = $rdf.graph();
......@@ -175,7 +173,6 @@ function loadRdfStoreFrom(source: DataSource): Promise<$rdf.Formula> {
source.contentType,
undefined
);
currentBrowser.storeCache[source.url] = store;
resolve(store);
} catch (err) {
reject(err);
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment