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:
parent
adbf819cc0
commit
04a6c36b5c
@ -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()));
|
||||
|
@ -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);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user