Compare commits

...

16 Commits

Author SHA1 Message Date
zadam
21e77c83fc release 0.37.8 2019-12-03 22:31:20 +01:00
zadam
b0310e34e2 fix CSS loading from subdomain, #741 2019-12-03 22:13:02 +01:00
zadam
761c51069a use max-height for promoted attributes, #739 2019-12-03 19:47:53 +01:00
zadam
4dc285d84f serve favicon from relative path 2019-12-03 19:31:58 +01:00
zadam
a1402c7c66 release 0.37.7 2019-12-02 23:09:42 +01:00
zadam
6ba3e5ab7f backport fix from master to avoid doubled attributes inherited from multiple paths 2019-12-02 23:07:19 +01:00
zadam
f740e52ebf correctly respect label @disableVersioning
(cherry picked from commit dc063983ea)
2019-12-02 23:06:06 +01:00
zadam
e9454e4db7 fix SQL console scrolling
(cherry picked from commit 749bb90713)
2019-12-02 23:05:05 +01:00
zadam
bfc7570e14 don't convert MD to HTML if "import markdown as text" is not selected, closes #733 2019-12-01 11:27:22 +01:00
zadam
5de92171a7 use owned attributes where it's a better fit 2019-12-01 10:28:05 +01:00
zadam
29c5e394ab generate document now creates also labels and relations 2019-12-01 10:20:18 +01:00
zadam
07b3d11fe5 fix generate new document script 2019-12-01 09:19:16 +01:00
zadam
67663fba50 fixes 2019-11-30 11:36:36 +01:00
zadam
995ebbf577 removed foreign keys PRAGMAs since foreign key constraints are not used anymore 2019-11-30 10:41:53 +01:00
zadam
d0e6be3e0c entity stat as part of consistency checks 2019-11-30 09:15:08 +01:00
zadam
01370a5968 fix anonymization according to latest schema 2019-11-29 21:42:24 +01:00
18 changed files with 99 additions and 67 deletions

2
package-lock.json generated
View File

@@ -1,6 +1,6 @@
{
"name": "trilium",
"version": "0.37.5",
"version": "0.37.7",
"lockfileVersion": 1,
"requires": true,
"dependencies": {

View File

@@ -2,7 +2,7 @@
"name": "trilium",
"productName": "Trilium Notes",
"description": "Trilium Notes",
"version": "0.37.6",
"version": "0.37.8",
"license": "AGPL-3.0-only",
"main": "electron.js",
"bin": {

View File

@@ -334,6 +334,11 @@ class Note extends Entity {
// we order by noteId so that attributes from same note stay together. Actual noteId ordering doesn't matter.
const filteredAttributes = attributes.filter((attr, index) => {
// if this exact attribute already appears then don't include it (can happen via cloning)
if (attributes.findIndex(it => it.attributeId === attr.attributeId) !== index) {
return false;
}
if (attr.isDefinition()) {
const firstDefinitionIndex = attributes.findIndex(el => el.type === attr.type && el.name === attr.name);

View File

@@ -78,7 +78,7 @@ window.onerror = function (msg, url, lineNo, columnNo, error) {
};
for (const appCssNoteId of window.appCssNoteIds) {
cssLoader.requireCss(`/api/notes/download/${appCssNoteId}`);
cssLoader.requireCss(`api/notes/download/${appCssNoteId}`);
}
const wikiBaseUrl = "https://github.com/zadam/trilium/wiki/";

View File

@@ -131,7 +131,7 @@ export default class ApperanceOptions {
if (noteId) {
// make sure the CSS is loaded
// if the CSS has been loaded and then updated then the changes won't take effect though
cssLoader.requireCss(`/api/notes/download/${noteId}`);
cssLoader.requireCss(`api/notes/download/${noteId}`);
}
this.$body.addClass("theme-" + newTheme);

View File

@@ -411,6 +411,10 @@ div.ui-tooltip {
height: 150px;
}
#sql-console-query .CodeMirror-scroll {
min-height: inherit !important;
}
.btn {
border-radius: var(--button-border-radius);
}
@@ -460,9 +464,10 @@ button.icon-button {
margin: auto;
/* setting the display to block since "table" doesn't support scrolling */
display: block;
flex-basis: content;
flex-shrink: 1;
/** flex-basis: content; - use once "content" is implemented by chrome */
flex-shrink: 0;
flex-grow: 0;
max-height: 30%;
overflow: auto;
}

View File

@@ -18,7 +18,10 @@ async function anonymize() {
await db.run("UPDATE notes SET title = 'title'");
await db.run("UPDATE note_contents SET content = 'text'");
await db.run("UPDATE note_revisions SET title = 'title', content = 'text'");
await db.run("UPDATE note_revisions SET title = 'title'");
await db.run("UPDATE note_revision_contents SET content = 'title'");
await db.run("UPDATE attributes SET name = 'name', value = 'value' WHERE type = 'label'");
await db.run("UPDATE attributes SET name = 'name' WHERE type = 'relation'");
await db.run("UPDATE branches SET prefix = 'prefix' WHERE prefix IS NOT NULL");
await db.run(`UPDATE options SET value = 'anonymized' WHERE name IN
('documentSecret', 'encryptedDataKey', 'passwordVerificationHash',

View File

@@ -1 +1 @@
module.exports = { buildDate:"2019-11-26T22:50:08+01:00", buildRevision: "5193f073e9e55f5440fe2e71fbd2cdfcdb2d2c6b" };
module.exports = { buildDate:"2019-12-03T22:31:20+01:00", buildRevision: "b0310e34e2c6f023cc8190310ff63d840157f6cc" };

View File

@@ -626,12 +626,31 @@ async function runAllChecks() {
return !unrecoveredConsistencyErrors;
}
async function showEntityStat(name, query) {
const map = await sql.getMap(query);
map[0] = map[0] || 0;
map[1] = map[1] || 0;
log.info(`${name} deleted: ${map[1]}, not deleted ${map[0]}`);
}
async function runDbDiagnostics() {
await showEntityStat("Notes", `SELECT isDeleted, count(noteId) FROM notes GROUP BY isDeleted`);
await showEntityStat("Note revisions", `SELECT isErased, count(noteRevisionId) FROM note_revisions GROUP BY isErased`);
await showEntityStat("Branches", `SELECT isDeleted, count(branchId) FROM branches GROUP BY isDeleted`);
await showEntityStat("Attributes", `SELECT isDeleted, count(attributeId) FROM attributes GROUP BY isDeleted`);
await showEntityStat("API tokens", `SELECT isDeleted, count(apiTokenId) FROM api_tokens GROUP BY isDeleted`);
}
async function runChecks() {
let elapsedTimeMs;
await syncMutexService.doExclusively(async () => {
const startTime = new Date();
await runDbDiagnostics();
await runAllChecks();
elapsedTimeMs = Date.now() - startTime.getTime();
@@ -663,7 +682,7 @@ sqlInit.dbReady.then(() => {
setInterval(cls.wrap(runChecks), 60 * 60 * 1000);
// kickoff checks soon after startup (to not block the initial load)
setTimeout(cls.wrap(runChecks), 10 * 1000);
setTimeout(cls.wrap(runChecks), 20 * 1000);
});
module.exports = {};

View File

@@ -81,7 +81,7 @@ eventService.subscribe(eventService.CHILD_NOTE_CREATED, async ({ parentNote, chi
async function processInverseRelations(entityName, entity, handler) {
if (entityName === 'attributes' && entity.type === 'relation') {
const note = await entity.getNote();
const attributes = (await note.getAttributes(entity.name)).filter(relation => relation.type === 'relation-definition');
const attributes = (await note.getOwnedAttributes(entity.name)).filter(relation => relation.type === 'relation-definition');
for (const attribute of attributes) {
const definition = attribute.value;

View File

@@ -12,9 +12,7 @@ const imageminGifLossy = require('imagemin-giflossy');
const jimp = require('jimp');
const imageType = require('image-type');
const sanitizeFilename = require('sanitize-filename');
const dateUtils = require('./date_utils');
const noteRevisionService = require('./note_revisions.js');
const NoteRevision = require("../entities/note_revision");
async function processImage(uploadBuffer, originalName, shrinkImageSwitch) {
const origImageFormat = imageType(uploadBuffer);

View File

@@ -258,7 +258,8 @@ async function importTar(taskContext, fileBuffer, importRootNote) {
content = content.toString("UTF-8");
}
if ((noteMeta && noteMeta.format === 'markdown') || (!noteMeta && ['text/markdown', 'text/x-markdown'].includes(mime))) {
if ((noteMeta && noteMeta.format === 'markdown')
|| (!noteMeta && taskContext.data.textImportedAsText && ['text/markdown', 'text/x-markdown'].includes(mime))) {
const parsed = mdReader.parse(content);
content = mdWriter.render(parsed);
}

View File

@@ -43,9 +43,6 @@ async function migrate() {
try {
log.info("Attempting migration to version " + mig.dbVersion);
// needs to happen outside of the transaction (otherwise it's a NO-OP)
await sql.execute("PRAGMA foreign_keys = OFF");
await sql.transactional(async () => {
if (mig.type === 'sql') {
const migrationSql = fs.readFileSync(resourceDir.MIGRATIONS_DIR + "/" + mig.file).toString('utf8');
@@ -76,10 +73,6 @@ async function migrate() {
utils.crash();
}
finally {
// make sure foreign keys are enabled even if migration script disables them
await sql.execute("PRAGMA foreign_keys = ON");
}
}
if (await sqlInit.isDbUpToDate()) {

View File

@@ -7,10 +7,6 @@ const dateUtils = require('../services/date_utils');
* @param {Note} note
*/
async function protectNoteRevisions(note) {
if (await note.hasLabel('disableVersioning')) {
return;
}
for (const revision of await note.getRevisions()) {
if (note.isProtected !== revision.isProtected) {
const content = await revision.getContent();
@@ -30,6 +26,10 @@ async function protectNoteRevisions(note) {
* @return {NoteRevision}
*/
async function createNoteRevision(note) {
if (await note.hasLabel("disableVersioning")) {
return;
}
const noteRevision = await new NoteRevision({
noteId: note.noteId,
// title and text should be decrypted now

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,
@@ -308,8 +308,7 @@ async function saveLinks(note, content) {
}
async function saveNoteRevision(note) {
// files and images are immutable, they can't be updated
// but we don't even version titles which is probably not correct
// files and images are versioned separately
if (note.type === 'file' || note.type === 'image' || await note.hasLabel('disableVersioning')) {
return;
}
@@ -480,7 +479,7 @@ async function eraseDeletedNotes() {
SET content = NULL,
utcDateModified = '${utcNowDateTime}'
WHERE noteRevisionId IN
(SELECT noteRevisionId FROM note_revisions WHERE isErased = 0 AND noteId IN ((???)))`, noteIdsToErase);
(SELECT noteRevisionId FROM note_revisions WHERE isErased = 0 AND noteId IN (???))`, noteIdsToErase);
await sql.executeMany(`
UPDATE note_revisions
@@ -514,7 +513,7 @@ async function duplicateNote(noteId, parentNoteId) {
notePosition: origBranch ? origBranch.notePosition + 1 : null
}).save();
for (const attribute of await origNote.getAttributes()) {
for (const attribute of await origNote.getOwnedAttributes()) {
const attr = new Attribute(attribute);
attr.attributeId = undefined; // force creation of new attribute
attr.noteId = newNote.noteId;

View File

@@ -57,8 +57,6 @@ async function initDbConnection() {
return;
}
await sql.execute("PRAGMA foreign_keys = ON");
const currentDbVersion = await getDbVersion();
if (currentDbVersion > appInfo.dbVersion) {
@@ -175,9 +173,11 @@ async function isDbUpToDate() {
}
async function dbInitialized() {
await optionService.setOption('initialized', 'true');
if (!await isDbInitialized()) {
await optionService.setOption('initialized', 'true');
await initDbConnection();
await initDbConnection();
}
}
dbReady.then(async () => {

View File

@@ -1,48 +1,32 @@
const fs = require('fs');
const dataDir = require('../services/data_dir');
fs.unlinkSync(dataDir.DOCUMENT_PATH);
/**
* Usage: node src/tools/generate_document.js 1000
* will create 1000 new notes and some clones into a current document.db
*/
require('../entities/entity_constructor');
const optionService = require('../services/options');
const sqlInit = require('../services/sql_init');
const myScryptService = require('../services/my_scrypt');
const passwordEncryptionService = require('../services/password_encryption');
const utils = require('../services/utils');
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');
async function setUserNamePassword() {
const username = "test";
const password = "test";
await optionService.setOption('username', username);
await optionService.setOption('passwordVerificationSalt', utils.randomSecureToken(32));
await optionService.setOption('passwordDerivedKeySalt', utils.randomSecureToken(32));
const passwordVerificationKey = utils.toBase64(await myScryptService.getVerificationHash(password));
await optionService.setOption('passwordVerificationHash', passwordVerificationKey);
await passwordEncryptionService.setDataKey(password, utils.randomSecureToken(16));
await sqlInit.initDbConnection();
}
const loremIpsum = require('lorem-ipsum').loremIpsum;
const noteCount = parseInt(process.argv[2]);
if (!noteCount) {
console.error(`Please enter number of notes as program parameter.`);
process.exit(1);
}
const notes = ['root'];
function getRandomParentNoteId() {
function getRandomNoteId() {
const index = Math.floor(Math.random() * notes.length);
return notes[index];
}
async function start() {
await setUserNamePassword();
for (let i = 0; i < noteCount; i++) {
const title = loremIpsum({ count: 1, units: 'sentences', sentenceLowerBound: 1, sentenceUpperBound: 10 });
@@ -50,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);
@@ -68,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);
}

View File

@@ -2,6 +2,7 @@
<html lang="en">
<head>
<meta charset="utf-8">
<link rel="shortcut icon" href="favicon.ico">
<title>Trilium Notes</title>
</head>
<body class="desktop theme-<%= theme %>" style="--main-font-size: <%= mainFontSize %>%; --tree-font-size: <%= treeFontSize %>%; --detail-font-size: <%= detailFontSize %>%;">