Skip to content

Build your personal knowledge base with Trilium Notes

cleanup/fixes of label/relation definition usages in the old style

zadam8b4cf474bd6c
diff --git a/src/entities/attribute.js b/src/entities/attribute.js
index f3ca773438..79c71f9f2b 100644
--- a/src/entities/attribute.js
+++ b/src/entities/attribute.js
@@ -30,14 +30,6 @@ class Attribute extends Entity {
super(row);
this.isInheritable = !!this.isInheritable;
-
- if (this.isDefinition()) {
- try {
- this.value = JSON.parse(this.value);
- }
- catch (e) {
- }
- }
}
/**
@@ -66,7 +58,7 @@ class Attribute extends Entity {
* @return {boolean}
*/
isDefinition() {
- return this.type === 'label-definition' || this.type === 'relation-definition';
+ return this.type === 'label' && (this.name.startsWith('label:') || this.name.startsWith('relation:'));
}
beforeSaving() {
diff --git a/src/entities/note.js b/src/entities/note.js
index 6ed2c9f01c..59bfc44801 100644
--- a/src/entities/note.js
+++ b/src/entities/note.js
@@ -9,9 +9,7 @@ const dateUtils = require('../services/date_utils');
const entityChangesService = require('../services/entity_changes.js');
const LABEL = 'label';
-const LABEL_DEFINITION = 'label-definition';
const RELATION = 'relation';
-const RELATION_DEFINITION = 'relation-definition';
/**
* This represents a Note which is a central object in the Trilium Notes project.
@@ -302,14 +300,6 @@ class Note extends Entity {
return this.getOwnedAttributes(LABEL, name);
}
- /**
- * @param {string} [name] - label name to filter
- * @returns {Attribute[]} all note's label definitions, including inherited ones
- */
- getLabelDefinitions(name) {
- return this.getAttributes(LABEL_DEFINITION, name);
- }
-
/**
* @param {string} [name] - relation name to filter
* @returns {Attribute[]} all note's relations (attributes with type relation), including inherited ones
@@ -341,14 +331,6 @@ class Note extends Entity {
return targets;
}
- /**
- * @param {string} [name] - relation name to filter
- * @returns {Attribute[]} all note's relation definitions including inherited ones
- */
- getRelationDefinitions(name) {
- return this.getAttributes(RELATION_DEFINITION, name);
- }
-
/**
* Clear note's attributes cache to force fresh reload for next attribute request.
* Cache is note instance scoped.
diff --git a/src/public/app/entities/note_short.js b/src/public/app/entities/note_short.js
index f4960adb25..d0a1744fb1 100644
--- a/src/public/app/entities/note_short.js
+++ b/src/public/app/entities/note_short.js
@@ -3,9 +3,7 @@ import Attribute from './attribute.js';
import noteAttributeCache from "../services/note_attribute_cache.js";
const LABEL = 'label';
-const LABEL_DEFINITION = 'label-definition';
const RELATION = 'relation';
-const RELATION_DEFINITION = 'relation-definition';
/**
* FIXME: since there's no "full note" anymore we can rename this to Note
@@ -243,14 +241,6 @@ class NoteShort {
return this.getAttributes(LABEL, name);
}
- /**
- * @param {string} [name] - label name to filter
- * @returns {Attribute[]} all note's label definitions, including inherited ones
- */
- getLabelDefinitions(name) {
- return this.getAttributes(LABEL_DEFINITION, name);
- }
-
/**
* @param {string} [name] - relation name to filter
* @returns {Attribute[]} all note's relations (attributes with type relation), including inherited ones
@@ -267,14 +257,6 @@ class NoteShort {
return this.getAttributes(RELATION, name);
}
- /**
- * @param {string} [name] - relation name to filter
- * @returns {Attribute[]} all note's relation definitions including inherited ones
- */
- getRelationDefinitions(name) {
- return this.getAttributes(RELATION_DEFINITION, name);
- }
-
/**
* @param {string} type - attribute type (label, relation, etc.)
* @param {string} name - attribute name
diff --git a/src/services/consistency_checks.js b/src/services/consistency_checks.js
index 63c068383f..c36a02591d 100644
--- a/src/services/consistency_checks.js
+++ b/src/services/consistency_checks.js
@@ -500,9 +500,7 @@ class ConsistencyChecks {
FROM attributes
WHERE isDeleted = 0
AND type != 'label'
- AND type != 'label-definition'
- AND type != 'relation'
- AND type != 'relation-definition'`,
+ AND type != 'relation'`,
({attributeId, type}) => {
if (this.autoFix) {
const attribute = repository.getAttribute(attributeId);
diff --git a/src/services/notes.js b/src/services/notes.js
index cdd2aa1fcd..87ddaff66c 100644
--- a/src/services/notes.js
+++ b/src/services/notes.js
@@ -464,6 +464,12 @@ function saveNoteRevision(note) {
const msSinceDateCreated = now.getTime() - dateUtils.parseDateTime(note.utcDateCreated).getTime();
if (!existingNoteRevisionId && msSinceDateCreated >= noteRevisionSnapshotTimeInterval * 1000) {
+ const content = note.getContent();
+
+ if (!content) {
+ return;
+ }
+
const noteRevision = new NoteRevision({
noteId: note.noteId,
// title and text should be decrypted now
@@ -478,7 +484,7 @@ function saveNoteRevision(note) {
dateCreated: dateUtils.localNowDateTime()
}).save();
- noteRevision.setContent(note.getContent());
+ noteRevision.setContent(content);
}
}