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

[ #22, MarkdownDB fails with more than 500 files in a top directory ] #95

Merged
merged 2 commits into from
Dec 18, 2023
Merged
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
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
Loading