You've already forked joplin
mirror of
https://github.com/laurent22/joplin.git
synced 2025-07-16 00:14:34 +02:00
Chore: Desktop: Add more ways to automatically populate the database
This commit is contained in:
@ -559,7 +559,12 @@ class Application extends BaseApplication {
|
|||||||
|
|
||||||
await SpellCheckerService.instance().initialize(new SpellCheckerServiceDriverNative());
|
await SpellCheckerService.instance().initialize(new SpellCheckerServiceDriverNative());
|
||||||
|
|
||||||
// await populateDatabase(reg.db());
|
// await populateDatabase(reg.db(), {
|
||||||
|
// clearDatabase: true,
|
||||||
|
// folderCount: 1000,
|
||||||
|
// rootFolderCount: 1,
|
||||||
|
// subFolderDepth: 1,
|
||||||
|
// });
|
||||||
|
|
||||||
// setTimeout(() => {
|
// setTimeout(() => {
|
||||||
// console.info(CommandService.instance().commandsToMarkdownTable(this.store().getState()));
|
// console.info(CommandService.instance().commandsToMarkdownTable(this.store().getState()));
|
||||||
|
@ -9,6 +9,8 @@ export interface Options {
|
|||||||
tagsPerNote?: number;
|
tagsPerNote?: number;
|
||||||
silent?: number;
|
silent?: number;
|
||||||
clearDatabase?: boolean;
|
clearDatabase?: boolean;
|
||||||
|
rootFolderCount?: number;
|
||||||
|
subFolderDepth?: number;
|
||||||
}
|
}
|
||||||
|
|
||||||
function randomIndex(array: any[]): number {
|
function randomIndex(array: any[]): number {
|
||||||
@ -47,6 +49,8 @@ export default async function populateDatabase(db: any, options: Options = null)
|
|||||||
tagCount: 0,
|
tagCount: 0,
|
||||||
tagsPerNote: 0,
|
tagsPerNote: 0,
|
||||||
clearDatabase: false,
|
clearDatabase: false,
|
||||||
|
rootFolderCount: 0,
|
||||||
|
subFolderDepth: 0,
|
||||||
...options,
|
...options,
|
||||||
};
|
};
|
||||||
|
|
||||||
@ -55,21 +59,45 @@ export default async function populateDatabase(db: any, options: Options = null)
|
|||||||
const createdFolderIds: string[] = [];
|
const createdFolderIds: string[] = [];
|
||||||
const createdNoteIds: string[] = [];
|
const createdNoteIds: string[] = [];
|
||||||
const createdTagIds: string[] = [];
|
const createdTagIds: string[] = [];
|
||||||
|
const createdFolderDepths: Record<string, number> = {};
|
||||||
|
const folderDepthToId: Record<number, string[]> = {};
|
||||||
|
let rootFolderCount: number = 0;
|
||||||
|
|
||||||
for (let i = 0; i < options.folderCount; i++) {
|
for (let i = 0; i < options.folderCount; i++) {
|
||||||
const folder: any = {
|
const folder: any = {
|
||||||
title: `folder${i}`,
|
title: `folder${i}`,
|
||||||
};
|
};
|
||||||
|
|
||||||
const isRoot = Math.random() <= 0.1 || i === 0;
|
let isRoot = Math.random() <= 0.1 || i === 0;
|
||||||
|
|
||||||
|
if (options.rootFolderCount && rootFolderCount >= options.rootFolderCount) isRoot = false;
|
||||||
|
|
||||||
|
let depth: number = 0;
|
||||||
|
|
||||||
if (!isRoot) {
|
if (!isRoot) {
|
||||||
const parentIndex = randomIndex(createdFolderIds);
|
let possibleFolderIds: string[] = [];
|
||||||
folder.parent_id = createdFolderIds[parentIndex];
|
if (options.subFolderDepth) {
|
||||||
|
for (let i = 0; i < options.subFolderDepth; i++) {
|
||||||
|
if (folderDepthToId[i]) possibleFolderIds = possibleFolderIds.concat(folderDepthToId[i]);
|
||||||
|
}
|
||||||
|
} else {
|
||||||
|
possibleFolderIds = createdFolderIds;
|
||||||
|
}
|
||||||
|
|
||||||
|
const parentIndex = randomIndex(possibleFolderIds);
|
||||||
|
const parentId = possibleFolderIds[parentIndex];
|
||||||
|
folder.parent_id = parentId;
|
||||||
|
depth = createdFolderDepths[parentId] + 1;
|
||||||
|
} else {
|
||||||
|
rootFolderCount++;
|
||||||
}
|
}
|
||||||
|
|
||||||
const savedFolder = await Folder.save(folder);
|
const savedFolder = await Folder.save(folder);
|
||||||
createdFolderIds.push(savedFolder.id);
|
createdFolderIds.push(savedFolder.id);
|
||||||
|
createdFolderDepths[savedFolder.id] = depth;
|
||||||
|
|
||||||
|
if (!folderDepthToId[depth]) folderDepthToId[depth] = [];
|
||||||
|
folderDepthToId[depth].push(savedFolder.id);
|
||||||
|
|
||||||
if (!options.silent) console.info(`Folders: ${i} / ${options.folderCount}`);
|
if (!options.silent) console.info(`Folders: ${i} / ${options.folderCount}`);
|
||||||
}
|
}
|
||||||
|
Reference in New Issue
Block a user