1
0
mirror of https://github.com/laurent22/joplin.git synced 2024-12-24 10:27:10 +02:00

Chore: Fixed populateDatabase tool

This commit is contained in:
Laurent Cozic 2024-03-28 15:35:27 +00:00
parent adbf819cc0
commit 04a6c36b5c
2 changed files with 20 additions and 50 deletions

View File

@ -628,12 +628,17 @@ class Application extends BaseApplication {
SearchEngine.instance().scheduleSyncTables();
});
// await populateDatabase(reg.db(), {
// setTimeout(() => {
// void populateDatabase(reg.db(), {
// clearDatabase: true,
// folderCount: 1000,
// rootFolderCount: 1,
// subFolderDepth: 1,
// folderCount: 200,
// noteCount: 3000,
// tagCount: 2000,
// tagsPerNote: 10,
// rootFolderCount: 20,
// subFolderDepth: 3,
// });
// }, 5000);
// setTimeout(() => {
// console.info(CommandService.instance().commandsToMarkdownTable(this.store().getState()));

View File

@ -103,66 +103,31 @@ export default async function populateDatabase(db: any, options: Options = null)
if (!options.silent) console.info(`Folders: ${i} / ${options.folderCount}`);
}
let tagBatch = [];
for (let i = 0; i < options.tagCount; i++) {
const tagTitle = randomElement(wordList); // `tag${i}`
// eslint-disable-next-line promise/prefer-await-to-then -- Old code before rule was applied
tagBatch.push(Tag.save({ title: tagTitle }, { dispatchUpdateAction: false }).then((savedTag: any) => {
const savedTag = await Tag.save({ title: tagTitle }, { dispatchUpdateAction: false });
createdTagIds.push(savedTag.id);
// eslint-disable-next-line no-console
if (!options.silent) console.info(`Tags: ${i} / ${options.tagCount}`);
}));
if (tagBatch.length > 1000) {
await Promise.all(tagBatch);
tagBatch = [];
}
}
if (tagBatch.length) {
await Promise.all(tagBatch);
tagBatch = [];
}
let noteBatch = [];
for (let i = 0; i < options.noteCount; i++) {
const note: any = { title: `note${i}`, body: `This is note num. ${i}` };
const parentIndex = randomIndex(createdFolderIds);
note.parent_id = createdFolderIds[parentIndex];
// eslint-disable-next-line promise/prefer-await-to-then -- Old code before rule was applied
noteBatch.push(Note.save(note, { dispatchUpdateAction: false }).then((savedNote: any) => {
const savedNote = await Note.save(note, { dispatchUpdateAction: false });
createdNoteIds.push(savedNote.id);
// eslint-disable-next-line no-console
console.info(`Notes: ${i} / ${options.noteCount}`);
}));
if (noteBatch.length > 1000) {
await Promise.all(noteBatch);
noteBatch = [];
}
}
if (noteBatch.length) {
await Promise.all(noteBatch);
noteBatch = [];
}
if (options.tagsPerNote) {
let noteTagBatch = [];
for (const noteId of createdNoteIds) {
const tagIds = randomElements(createdTagIds, options.tagsPerNote);
noteTagBatch.push(Tag.setNoteTagsByIds(noteId, tagIds));
if (noteTagBatch.length > 1000) {
await Promise.all(noteTagBatch);
noteTagBatch = [];
}
}
if (noteTagBatch.length) {
await Promise.all(noteTagBatch);
noteTagBatch = [];
await Tag.setNoteTagsByIds(noteId, tagIds);
}
}
}