2019-12-01 16:19:16 +08:00
|
|
|
/**
|
|
|
|
* Usage: node src/tools/generate_document.js 1000
|
|
|
|
* will create 1000 new notes and some clones into a current document.db
|
|
|
|
*/
|
2018-04-04 10:15:28 +08:00
|
|
|
|
|
|
|
require('../entities/entity_constructor');
|
|
|
|
const sqlInit = require('../services/sql_init');
|
|
|
|
const noteService = require('../services/notes');
|
2019-12-01 17:20:18 +08:00
|
|
|
const attributeService = require('../services/attributes');
|
2018-04-04 10:15:28 +08:00
|
|
|
const cls = require('../services/cls');
|
|
|
|
const cloningService = require('../services/cloning');
|
2019-12-01 16:19:16 +08:00
|
|
|
const loremIpsum = require('lorem-ipsum').loremIpsum;
|
2018-04-04 10:15:28 +08:00
|
|
|
|
2019-12-01 16:19:16 +08:00
|
|
|
const noteCount = parseInt(process.argv[2]);
|
2018-04-04 10:15:28 +08:00
|
|
|
|
2019-12-01 16:19:16 +08:00
|
|
|
if (!noteCount) {
|
|
|
|
console.error(`Please enter number of notes as program parameter.`);
|
|
|
|
process.exit(1);
|
2018-04-04 10:15:28 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
const notes = ['root'];
|
|
|
|
|
2019-12-01 17:20:18 +08:00
|
|
|
function getRandomNoteId() {
|
2018-04-04 10:15:28 +08:00
|
|
|
const index = Math.floor(Math.random() * notes.length);
|
|
|
|
|
|
|
|
return notes[index];
|
|
|
|
}
|
|
|
|
|
|
|
|
async function start() {
|
|
|
|
for (let i = 0; i < noteCount; i++) {
|
|
|
|
const title = loremIpsum({ count: 1, units: 'sentences', sentenceLowerBound: 1, sentenceUpperBound: 10 });
|
|
|
|
|
|
|
|
const paragraphCount = Math.floor(Math.random() * Math.random() * 100);
|
|
|
|
const content = loremIpsum({ count: paragraphCount, units: 'paragraphs', sentenceLowerBound: 1, sentenceUpperBound: 15,
|
|
|
|
paragraphLowerBound: 3, paragraphUpperBound: 10, format: 'html' });
|
|
|
|
|
2019-11-16 18:09:52 +08:00
|
|
|
const {note} = await noteService.createNewNote({
|
2019-12-01 17:32:30 +08:00
|
|
|
parentNoteId: getRandomNoteId(),
|
2019-11-16 18:09:52 +08:00
|
|
|
title,
|
|
|
|
content,
|
|
|
|
type: 'text'
|
|
|
|
});
|
2018-04-04 10:15:28 +08:00
|
|
|
|
|
|
|
console.log(`Created note ${i}: ${title}`);
|
|
|
|
|
|
|
|
notes.push(note.noteId);
|
|
|
|
}
|
|
|
|
|
2019-12-01 17:20:18 +08:00
|
|
|
// we'll create clones for 4% of notes
|
|
|
|
for (let i = 0; i < (noteCount / 25); i++) {
|
|
|
|
const noteIdToClone = getRandomNoteId();
|
|
|
|
const parentNoteId = getRandomNoteId();
|
2018-04-04 10:15:28 +08:00
|
|
|
const prefix = Math.random() > 0.8 ? "prefix" : null;
|
|
|
|
|
|
|
|
const result = await cloningService.cloneNoteToParent(noteIdToClone, parentNoteId, prefix);
|
|
|
|
|
|
|
|
console.log(`Cloning ${i}:`, result.success ? "succeeded" : "FAILED");
|
|
|
|
}
|
|
|
|
|
2019-12-01 17:20:18 +08:00
|
|
|
for (let i = 0; i < noteCount; i++) {
|
|
|
|
await attributeService.createAttribute({
|
|
|
|
noteId: getRandomNoteId(),
|
|
|
|
type: 'label',
|
|
|
|
name: 'label',
|
|
|
|
value: 'value',
|
|
|
|
isInheritable: Math.random() > 0.1 // 10% are inheritable
|
|
|
|
});
|
|
|
|
|
|
|
|
console.log(`Creating label ${i}`);
|
|
|
|
}
|
|
|
|
|
|
|
|
for (let i = 0; i < noteCount; i++) {
|
|
|
|
await attributeService.createAttribute({
|
|
|
|
noteId: getRandomNoteId(),
|
|
|
|
type: 'relation',
|
|
|
|
name: 'relation',
|
|
|
|
value: getRandomNoteId(),
|
|
|
|
isInheritable: Math.random() > 0.1 // 10% are inheritable
|
|
|
|
});
|
|
|
|
|
|
|
|
console.log(`Creating relation ${i}`);
|
|
|
|
}
|
|
|
|
|
2018-04-04 10:15:28 +08:00
|
|
|
process.exit(0);
|
|
|
|
}
|
|
|
|
|
2018-07-23 01:56:20 +08:00
|
|
|
sqlInit.dbReady.then(cls.wrap(start));
|