Skip to content

Commit

Permalink
[ #22, MarkdownDB fails with more than 500 files in a top directory ]
Browse files Browse the repository at this point in the history
  • Loading branch information
mohamedsalem401 committed Dec 18, 2023
1 parent ea5d036 commit e0e5156
Showing 1 changed file with 41 additions and 4 deletions.
45 changes: 41 additions & 4 deletions src/lib/schema.ts
Original file line number Diff line number Diff line change
Expand Up @@ -123,7 +123,17 @@ class MddbFile {
return serializedFile;
});

return db.batchInsert(Table.Files, serializedFiles);
if (serializedFiles.length >= 500) {
const promises = [];
for (let i = 0; i < serializedFiles.length; i += 500) {
promises.push(
db.batchInsert(Table.Files, serializedFiles.slice(i, i + 500))
);
}
return Promise.all(promises);
} else {
return db.batchInsert(Table.Files, serializedFiles);
}
}
}

Expand Down Expand Up @@ -178,7 +188,15 @@ class MddbLink {
}

static batchInsert(db: Knex, links: Link[]) {
return db.batchInsert(Table.Links, links);
if (links.length >= 500) {
const promises = [];
for (let i = 0; i < links.length; i += 500) {
promises.push(db.batchInsert(Table.Links, links.slice(i, i + 500)));
}
return Promise.all(promises);
} else {
return db.batchInsert(Table.Links, links);
}
}
}

Expand Down Expand Up @@ -225,7 +243,16 @@ class MddbTag {
if (!areUniqueObjectsByKey(tags, "name")) {
throw new Error("Tags must have unique name");
}
return db.batchInsert(Table.Tags, tags);

if (tags.length >= 500) {
const promises = [];
for (let i = 0; i < tags.length; i += 500) {
promises.push(db.batchInsert(Table.Tags, tags.slice(i, i + 500)));
}
return Promise.all(promises);
} else {
return db.batchInsert(Table.Tags, tags);
}
}
}

Expand Down Expand Up @@ -266,7 +293,17 @@ class MddbFileTag {
}

static batchInsert(db: Knex, fileTags: FileTag[]) {
return db.batchInsert(Table.FileTags, fileTags);
if (fileTags.length >= 500) {
const promises = [];
for (let i = 0; i < fileTags.length; i += 500) {
promises.push(
db.batchInsert(Table.FileTags, fileTags.slice(i, i + 500))
);
}
return Promise.all(promises);
} else {
return db.batchInsert(Table.FileTags, fileTags);
}
}
}

Expand Down

0 comments on commit e0e5156

Please sign in to comment.