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

Add override option to force reloading a source #13

Open
wants to merge 2 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
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
10 changes: 7 additions & 3 deletions addon/initializers/rdf-store.js
Original file line number Diff line number Diff line change
Expand Up @@ -88,7 +88,10 @@ class StoreService extends Service {
addAll() { return this.store.addAll(...arguments); }
removeStatements() { return this.store.removeStatements(...arguments); }
removeMatches() { return this.store.removeMatches(...arguments); }
async load(source) { return await this.store.load(source); }
async load(source, override) {
if (override) this.storeCache = {};
return await this.store.load(source, override);
}
async update(deletes, inserts) { return await this.store.update(deletes, inserts); }
async persist() { return await this.store.persist(); }

Expand Down Expand Up @@ -200,18 +203,19 @@ class StoreService extends Service {
* Fetches the graph for a specific model (type)
*
* @param {String} model The given model
* @param override whether to force reload of the model.
*
* @method
*/
async fetchGraphForType(model) {
async fetchGraphForType(model, override = false) {
const klass = classForModel(getOwner(this), model);
if (!klass.rdfType)
console.error(`Tried to fetch all instances of ${model} but it has no @rdfType annotation.`);

const sourceGraph = this.discoverDefaultGraphByType(klass);

try {
await this.load(sourceGraph);
await this.load(sourceGraph, override);
} catch (e) {
console.log(`Failed to fetch ${sourceGraph.value}`);
console.log(e);
Expand Down
12 changes: 9 additions & 3 deletions addon/utils/forking-store.js
Original file line number Diff line number Diff line change
Expand Up @@ -101,11 +101,17 @@ export default class ForkingStore {
/**
* Load data from an external graph.
* @param {NamedNode} source the online source from which the triples will be loaded into local store.
* @param override whether to clear all current changes in this graph before loading from the server.
* @memberof {ForkingStore}
*/
async load(source) {
// TODO: should we remove our changes when a graph is being reloaded?
await this.fetcher.load(source);
async load(source, override = false) {
if (override) {
// clear the graph and then refill it
this.graph.removeMany(null, null, null, source);
this.removeMatches(null, null, null, addGraphFor(source));
this.removeMatches(null, null, null, delGraphFor(source));
}
await this.fetcher.load(source, { force: override });
}

/**
Expand Down