Commit 0c2f29dd authored by Laurent Wouters's avatar Laurent Wouters
Browse files

[fix] Use cache for RDF data store loading

parent ac981ef78ac9
......@@ -705,28 +705,6 @@ export function selectPrimaryTopic(resource: ResourceData): string {
}
}
/**
* The data of an LD browser
*/
export class LDBrowserData {
constructor(observation: ResourceObservedData) {
let init = new ResourceData();
init.observations = observation;
init.command = new ResourceUserCommand();
this.history = [init];
this.byResource = {};
this.byResource[observation.url] = init;
}
/**
* The history of resources
*/
history: ResourceData[];
/**
* The data for each known resource
*/
byResource: { [url: string]: ResourceData };
}
/**
* Tries to negotiate data content at the specified URL
*/
......
......@@ -23,7 +23,6 @@ import * as $rdf from "rdflib";
import { application, definition, implementation } from "@logilab/libview";
import * as LANGUAGES from "../common/data.iso639.json";
import {
LDBrowserData,
ResourceObservedData,
ResourceData,
fetchSource,
......@@ -45,6 +44,32 @@ import {
} from "../common/messages";
require("./view-defaults-impl");
/**
* The data of an LD browser
*/
class LDBrowserData {
constructor(observation: ResourceObservedData) {
let init = new ResourceData();
init.observations = observation;
init.command = new ResourceUserCommand();
this.history = [init];
this.byResource = {};
this.byResource[observation.url] = init;
}
/**
* The history of resources
*/
history: ResourceData[];
/**
* The data for each known resource
*/
byResource: { [url: string]: ResourceData };
/**
* The cache of loaded RDF data
*/
storeCache: { [url: string]: $rdf.Formula };
}
/**
* Get the value of an HTTP parameter
* @param name The name of the parameter to retrieve
......@@ -134,24 +159,31 @@ 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 p1 = fetchSource(source);
p1.then((value: RawContent) => {
let store = $rdf.graph();
try {
$rdf.parse(
value.content,
store,
source.url,
source.contentType,
undefined
);
resolve(store);
} catch (err) {
reject(err);
}
}).catch(reason => {
reject(reason);
});
let cached = currentBrowser.storeCache[source.url];
if (cached != null && cached != undefined) {
resolve(cached);
return;
}
fetchSource(source)
.then((value: RawContent) => {
let store = $rdf.graph();
try {
$rdf.parse(
value.content,
store,
source.url,
source.contentType,
undefined
);
currentBrowser.storeCache[source.url] = store;
resolve(store);
} catch (err) {
reject(err);
}
})
.catch(reason => {
reject(reason);
});
}
);
}
......
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