Skip to content

Commit

Permalink
Rework KC insert to insert in KA chunks
Browse files Browse the repository at this point in the history
  • Loading branch information
Mihajlo-Pavlovic committed Jan 28, 2025
1 parent 2424882 commit 45a5bd3
Show file tree
Hide file tree
Showing 2 changed files with 38 additions and 14 deletions.
50 changes: 37 additions & 13 deletions src/modules/triple-store/implementation/ot-triple-store.js
Original file line number Diff line number Diff line change
Expand Up @@ -270,23 +270,47 @@ class OtTripleStore {
return this.ask(repository, query);
}

async createKnowledgeCollectionNamedGraphs(repository, uals, assetsNQuads, visibility) {
const query = `
PREFIX schema: <${SCHEMA_CONTEXT}>
INSERT DATA {
${uals
.map(
(ual, index) => `
async createKnowledgeCollectionNamedGraphs(
repository,
uals,
assetsNQuads,
visibility,
retries = 5,
retryDelay = 10,
) {
const queries = uals.map(
(ual, index) => `
PREFIX schema: <${SCHEMA_CONTEXT}>
INSERT DATA {
GRAPH <${ual}/${visibility}> {
${assetsNQuads[index].join('\n')}
}
`,
)
.join('\n')}
}
`,
);
for (const [index, query] of queries.entries()) {
let attempts = 0;
let success = false;

while (attempts < retries && !success) {
try {
await this.queryVoid(repository, query);
success = true;
} catch (error) {
attempts += 1;
if (attempts < retries) {
this.logger.warn(
`Insert failed for GRAPH <${uals[index]}/${visibility}>. Attempt ${attempts}/${retries}. Retrying in ${retryDelay}ms.`,
);
await setTimeout(retryDelay);
} else {
throw new Error(
`Failed to insert into GRAPH <${uals[index]}/${visibility}> after ${retries} attempts.`,
);
}
}
}
`;

await this.queryVoid(repository, query);
}
}

async deleteKnowledgeCollectionNamedGraphs(repository, uals) {
Expand Down
2 changes: 1 addition & 1 deletion src/service/triple-store-service.js
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@ class TripleStoreService {
knowledgeCollectionUAL,
triples,
retries = 5,
retryDelay = 0,
retryDelay = 50,
) {
this.logger.info(
`Inserting Knowledge Collection with the UAL: ${knowledgeCollectionUAL} ` +
Expand Down

0 comments on commit 45a5bd3

Please sign in to comment.