generate document now creates also labels and relations

This commit is contained in:
zadam 2019-12-01 10:20:18 +01:00
parent 07b3d11fe5
commit 29c5e394ab
2 changed files with 32 additions and 7 deletions

View file

@ -117,7 +117,7 @@ async function createNewNote(parentNoteId, noteData) {
isExpanded: !!noteData.isExpanded
}).save();
for (const attr of await parentNote.getAttributes()) {
for (const attr of await parentNote.getOwnedAttributes()) {
if (attr.name.startsWith("child:")) {
await new Attribute({
noteId: note.noteId,

View file

@ -6,6 +6,7 @@
require('../entities/entity_constructor');
const sqlInit = require('../services/sql_init');
const noteService = require('../services/notes');
const attributeService = require('../services/attributes');
const cls = require('../services/cls');
const cloningService = require('../services/cloning');
const loremIpsum = require('lorem-ipsum').loremIpsum;
@ -19,7 +20,7 @@ if (!noteCount) {
const notes = ['root'];
function getRandomParentNoteId() {
function getRandomNoteId() {
const index = Math.floor(Math.random() * notes.length);
return notes[index];
@ -33,17 +34,17 @@ async function start() {
const content = loremIpsum({ count: paragraphCount, units: 'paragraphs', sentenceLowerBound: 1, sentenceUpperBound: 15,
paragraphLowerBound: 3, paragraphUpperBound: 10, format: 'html' });
const {note} = await noteService.createNote(getRandomParentNoteId(), title, content);
const {note} = await noteService.createNote(getRandomNoteId(), title, content);
console.log(`Created note ${i}: ${title}`);
notes.push(note.noteId);
}
// we'll create clones for 20% of notes
for (let i = 0; i < (noteCount / 50); i++) {
const noteIdToClone = getRandomParentNoteId();
const parentNoteId = getRandomParentNoteId();
// we'll create clones for 4% of notes
for (let i = 0; i < (noteCount / 25); i++) {
const noteIdToClone = getRandomNoteId();
const parentNoteId = getRandomNoteId();
const prefix = Math.random() > 0.8 ? "prefix" : null;
const result = await cloningService.cloneNoteToParent(noteIdToClone, parentNoteId, prefix);
@ -51,6 +52,30 @@ async function start() {
console.log(`Cloning ${i}:`, result.success ? "succeeded" : "FAILED");
}
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}`);
}
process.exit(0);
}