Skip to content

Commit

Permalink
KAS-1265 redo lost code after refactor
Browse files Browse the repository at this point in the history
  • Loading branch information
ValenberghsSven committed Feb 25, 2020
2 parents f1ff2ee + e5ad8b3 commit ed8ac04
Show file tree
Hide file tree
Showing 4 changed files with 26 additions and 31 deletions.
15 changes: 10 additions & 5 deletions app.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,14 +3,14 @@ const app = mu.app;
const bodyParser = require('body-parser');
const cors = require('cors');
import {handleDelta} from './handle-deltas';
import {directQuery, configurableQuery} from './repository/helpers';
import { cleanup, directQuery, configurableQuery} from './repository/helpers';

const fillInterneOverheid = require('./repository/fill-intern-overheid');
const fillInterneRegering = require('./repository/fill-intern-regering');
const fillPublic = require('./repository/fill-public');

if (!process.env.DIRECT_ENDPOINT) {
throw new Error("DIRECT_ENDPOINT not set!")
throw new Error("DIRECT_ENDPOINT not set!");
}

app.use(bodyParser.json({ type: 'application/json' , limit: '50mb' }));
Expand Down Expand Up @@ -59,7 +59,7 @@ const builders = {
}
};

const initialLoad = function(){
async function initialLoad(){
let toFillUp = '';
if(process.env.RELOAD_ALL_DATA_ON_INIT == "true") {
toFillUp = 'public,intern-overheid,intern-regering,minister';
Expand Down Expand Up @@ -88,10 +88,15 @@ const initialLoad = function(){
}
}
};
fillAll();
await fillAll();
};

initialLoad();
async function startup() {
await cleanup();
await initialLoad();
}

startup();

const deltaBuilders = Object.assign({}, builders);
delete deltaBuilders.public;
Expand Down
6 changes: 2 additions & 4 deletions repository/fill-intern-overheid.js
Original file line number Diff line number Diff line change
Expand Up @@ -91,15 +91,13 @@ export const fillUp = async (queryEnv, agendas) => {
await runStage('copy temp to target', queryEnv, () => {
return copyTempToTarget(queryEnv);
});
await runStage('done filling overheid', queryEnv, () => {
return cleanup(queryEnv);
});
await runStage('done filling overheid', queryEnv, cleanup);
const end = moment().utc();
logStage(start, `fill overheid ended at: ${end.format()}`, targetGraph);
} catch (e) {
logStage(moment(), `${e}\n${e.stack}`, queryEnv.targetGraph);
try {
cleanup(queryEnv);
await cleanup(queryEnv);
} catch (e2) {
console.log(e2);
}
Expand Down
8 changes: 3 additions & 5 deletions repository/fill-intern-regering.js
Original file line number Diff line number Diff line change
Expand Up @@ -82,17 +82,15 @@ export const fillUp = async (queryEnv, agendas) => {
await runStage('copy temp to target', queryEnv, () => {
return copyTempToTarget(queryEnv);
});
await runStage('cleaned up', queryEnv, () => {
return cleanup(queryEnv);
});
await runStage('cleaned up', queryEnv, cleanup);
const end = moment().utc();
logStage(start, `fill regering ended at: ${end.format()}`, targetGraph);
}catch (e) {
logStage(moment(), `${e}\n${e.stack}`, queryEnv.targetGraph);
try {
cleanup(queryEnv);
await cleanup(queryEnv);
}catch (e2) {
console.log(e2);
}
}
};
};
28 changes: 11 additions & 17 deletions repository/helpers.js
Original file line number Diff line number Diff line change
Expand Up @@ -129,22 +129,16 @@ const addRelatedFiles = (queryEnv, extraFilters) => {
return queryEnv.run(query, true);
};

const cleanup = (queryEnv) => {
// TODO should we not batch this delete?
const query = `
PREFIX ext: <http://mu.semte.ch/vocabularies/ext/>
DELETE {
GRAPH ?g {
?s ?p ?o.
}
} WHERE {
GRAPH ?g {
?g a ext:TempGraph .
?s ?p ?o.
}
}`;
return queryEnv.run(query, true);
};
async function cleanup() {
const result = JSON.parse(await directQuery("PREFIX ext: <http://mu.semte.ch/vocabularies/ext/> SELECT ?g WHERE { GRAPH ?g { ?g a ext:TempGraph }}"));
if (result.results && result.results.bindings) {
console.log(`found ${result.results.bindings.length} old temporary graphs, removing before going further`);
for (let binding of result.results.bindings) {
console.log(`dropping graph ${binding.g.value}`);
await directQuery(`DROP SILENT GRAPH <${binding.g.value}>`);
}
}
}

const fillOutDetailsOnVisibleItemsLeft = async (queryEnv) => {
const result = await queryEnv.run(`
Expand Down Expand Up @@ -892,7 +886,7 @@ const configurableQuery = function(queryString, direct){
}, queryString);
};

const directQuery = function(queryString){
function directQuery(queryString){
return configurableQuery(queryString, true);
};

Expand Down

0 comments on commit ed8ac04

Please sign in to comment.