avoid inserting duplicate triples to the database

This commit is contained in:
Oscar
2024-04-23 12:51:04 +02:00
parent 09d499fc01
commit 449204a9d1
2 changed files with 13 additions and 15 deletions

View File

@@ -53,7 +53,7 @@ async function dispatch(lib, data) {
}
function separateBetweenTargetAndPublic(changes, context) {
const changesOnPublic = [];
const changesOnPublic = new Set();
const changesOnGraphs = {};
for(let change of changes) {
const subject = change.subject;
@@ -71,18 +71,16 @@ function separateBetweenTargetAndPublic(changes, context) {
const graph = graphTriple.object.slice(1,-1); // We have to slice it to remove the "<" and ">"
if(change.object !== '') {
if(!changesOnGraphs[graph]) {
changesOnGraphs[graph] = [`${change.subject} ${change.predicate} ${change.object}.`]
} else {
changesOnGraphs[graph].push(`${change.subject} ${change.predicate} ${change.object}.`)
}
changesOnGraphs[graph] = new Set();
}
changesOnGraphs[graph].add(`${change.subject} ${change.predicate} ${change.object}.`)
}
for(let triple of otherContextTriples) {
if(triple.object === '') continue;
if(!changesOnGraphs[graph]) {
changesOnGraphs[graph] = [`${triple.subject} ${triple.predicate} ${triple.object}.`]
} else {
changesOnGraphs[graph].push(`${triple.subject} ${triple.predicate} ${triple.object}.`)
}
changesOnGraphs[graph] = new Set();
}
changesOnGraphs[graph].add(`${triple.subject} ${triple.predicate} ${triple.object}.`)
}
}
const typeTriple = contextTriples.find(
@@ -92,9 +90,9 @@ function separateBetweenTargetAndPublic(changes, context) {
if(!typeTriple) continue;
const type = typeTriple.object;
if(publicTypes.includes(type)) {
changesOnPublic.push(`${change.subject} ${change.predicate} ${change.object}.`)
changesOnPublic.add(`${change.subject} ${change.predicate} ${change.object}.`)
for(let triple of otherContextTriples) {
changesOnPublic.push(`${triple.subject} ${triple.predicate} ${triple.object}.`)
changesOnPublic.add(`${triple.subject} ${triple.predicate} ${triple.object}.`)
}
}
}

View File

@@ -91,7 +91,7 @@ async function insertIntoPublicGraph(lib, statements) {
await batchedDbUpdate(
lib.muAuthSudo.updateSudo,
'http://mu.semte.ch/graphs/public',
statements,
Array.from(statements),
{},
process.env.MU_SPARQL_ENDPOINT,
BATCH_SIZE,
@@ -108,7 +108,7 @@ async function insertIntoSpecificGraphs(lib, statementsWithGraphs) {
await batchedDbUpdate(
lib.muAuthSudo.updateSudo,
graph,
statementsWithGraphs[graph],
Array.from(statementsWithGraphs[graph]),
{},
process.env.MU_SPARQL_ENDPOINT,
BATCH_SIZE,
@@ -126,7 +126,7 @@ async function deleteFromPublicGraph(lib, statements) {
await batchedDbUpdate(
lib.muAuthSudo.updateSudo,
'http://mu.semte.ch/graphs/public',
statements,
Array.from(statements),
{},
process.env.MU_SPARQL_ENDPOINT,
BATCH_SIZE,
@@ -144,7 +144,7 @@ async function deleteFromSpecificGraphs(lib, statementsWithGraphs) {
await batchedDbUpdate(
lib.muAuthSudo.updateSudo,
graph,
statementsWithGraphs[graph],
Array.from(statementsWithGraphs[graph]),
{},
process.env.MU_SPARQL_ENDPOINT,
BATCH_SIZE,