diff --git a/.idea/dataSources/a2c75661-f9e2-478f-a69f-6a9409e69997.xml b/.idea/dataSources/a2c75661-f9e2-478f-a69f-6a9409e69997.xml
index 55a6521fe..ae7ed066d 100644
--- a/.idea/dataSources/a2c75661-f9e2-478f-a69f-6a9409e69997.xml
+++ b/.idea/dataSources/a2c75661-f9e2-478f-a69f-6a9409e69997.xml
@@ -131,562 +131,535 @@
1
-
+
noteId
-
- noteId
-
-
-
+
name
value
-
+
name
-
- name
-
-
-
+
value
-
- value
-
-
-
+
attributeId
1
sqlite_autoindex_attributes_1
-
+
1
TEXT|0s
1
-
+
2
TEXT|0s
1
-
+
3
TEXT|0s
1
-
+
4
INTEGER|0s
1
-
+
5
TEXT|0s
-
+
6
BOOLEAN|0s
-
+
7
INTEGER|0s
1
0
-
+
8
TEXT|0s
1
-
+
9
TEXT|0s
1
""
-
+
10
TEXT|0s
1
'1970-01-01T00:00:00.000Z'
-
+
1
branchId
1
-
+
noteId
parentNoteId
-
+
noteId
-
+
parentNoteId
-
+
branchId
1
sqlite_autoindex_branches_1
-
+
1
TEXT|0s
1
-
+
2
TEXT|0s
-
+
3
TEXT|0s
-
+
4
TEXT|0s
1
-
+
1
eventId
1
-
- noteId
-
-
-
+
eventId
1
sqlite_autoindex_event_log_1
-
+
1
TEXT|0s
1
-
+
2
TEXT|0s
1
-
+
3
TEXT|0s
1
-
+
4
TEXT|0s
1
-
+
5
TEXT|0s
1
""
-
+
6
INTEGER|0s
1
0
-
+
7
TEXT|0s
1
-
+
8
TEXT|0s
1
-
+
1
linkId
1
-
+
noteId
-
- noteId
-
-
-
+
targetNoteId
-
- targetNoteId
-
-
-
+
linkId
1
sqlite_autoindex_links_1
-
+
1
TEXT|0s
1
-
+
2
TEXT|0s
1
-
+
3
INT|0s
1
0
-
+
4
TEXT|0s
NULL
-
+
5
TEXT|0s
1
""
-
+
1
noteContentId
1
-
+
noteId
+ 1
-
+
noteContentId
1
sqlite_autoindex_note_contents_1
-
+
1
TEXT|0s
1
-
+
2
TEXT|0s
1
-
+
3
TEXT|0s
-
+
4
TEXT|0s
-
+
5
INT|0s
1
0
-
+
6
TEXT|0s
1
-
+
7
TEXT|0s
1
-
+
8
TEXT|0s
1
''
-
+
9
TEXT|0s
1
''
-
+
10
TEXT|0s
1
""
-
+
1
noteRevisionId
1
-
+
noteId
-
+
dateModifiedFrom
-
+
dateModifiedTo
-
+
noteRevisionId
1
sqlite_autoindex_note_revisions_1
-
+
1
TEXT|0s
1
-
+
2
TEXT|0s
1
"note"
-
+
3
INT|0s
1
0
-
+
4
TEXT|0s
1
'text'
-
+
5
TEXT|0s
1
'text/html'
-
+
6
TEXT|0s
1
""
-
+
7
INT|0s
1
0
-
+
8
TEXT|0s
1
-
+
9
TEXT|0s
1
-
+
1
noteId
1
-
- isDeleted
-
-
-
+
noteId
1
sqlite_autoindex_notes_1
-
+
1
TEXT|0s
1
-
+
2
TEXT|0s
-
+
3
INT|0s
-
+
4
INTEGER|0s
1
0
-
+
5
TEXT|0s
1
""
-
+
6
TEXT|0s
1
'1970-01-01T00:00:00.000Z'
-
+
1
name
1
-
+
name
1
sqlite_autoindex_options_1
-
+
1
TEXT|0s
1
-
+
2
TEXT|0s
1
-
+
3
TEXT|0s
1
""
-
+
4
TEXT|0s
1
-
+
5
INT|0s
-
+
1
branchId
1
-
+
branchId
1
sqlite_autoindex_recent_notes_1
-
+
1
TEXT|0s
1
-
+
2
TEXT|0s
1
-
+
1
sourceId
1
-
+
sourceId
1
sqlite_autoindex_source_ids_1
-
+
1
text|0s
-
+
2
text|0s
-
+
3
text|0s
-
+
4
integer|0s
-
+
5
text|0s
-
+
1
-
+
2
-
+
1
INTEGER|0s
1
1
-
+
2
TEXT|0s
1
-
+
3
TEXT|0s
1
-
+
4
TEXT|0s
1
-
+
5
TEXT|0s
1
-
+
entityName
entityId
1
-
+
syncDate
-
+
id
1
diff --git a/db/migrations/0125__create_note_content_table.sql b/db/migrations/0125__create_note_content_table.sql
index ef5ebd4fc..53c38487f 100644
--- a/db/migrations/0125__create_note_content_table.sql
+++ b/db/migrations/0125__create_note_content_table.sql
@@ -31,5 +31,3 @@ SELECT noteId, title, isProtected, isDeleted, dateCreated, dateModified, type, m
DROP TABLE notes;
ALTER TABLE notes_mig RENAME TO notes;
-
-CREATE INDEX `IDX_notes_isDeleted` ON `notes` (`isDeleted`);
\ No newline at end of file
diff --git a/db/migrations/0126__create_missing_indexes.sql b/db/migrations/0126__create_missing_indexes.sql
deleted file mode 100644
index 1d7a1be87..000000000
--- a/db/migrations/0126__create_missing_indexes.sql
+++ /dev/null
@@ -1,8 +0,0 @@
-CREATE INDEX `IDX_attributes_noteId` ON `attributes` (`noteId`);
-CREATE INDEX `IDX_attributes_name` ON `attributes` (`name`);
-CREATE INDEX `IDX_attributes_value` ON `attributes` (`value`);
-
-CREATE INDEX `IDX_event_log_noteId` ON `event_log` (`noteId`);
-
-CREATE INDEX `IDX_links_noteId` ON `links` (`noteId`);
-CREATE INDEX `IDX_links_targetNoteId` ON `links` (`targetNoteId`);
diff --git a/src/entities/entity.js b/src/entities/entity.js
index 9f1962edd..e88f5ca50 100644
--- a/src/entities/entity.js
+++ b/src/entities/entity.js
@@ -8,7 +8,10 @@ class Entity {
*/
constructor(row = {}) {
for (const key in row) {
- this[key] = row[key];
+ // ! is used when joint-fetching notes and note_contents objects for performance
+ if (!key.startsWith('!')) {
+ this[key] = row[key];
+ }
}
if ('isDeleted' in this) {
diff --git a/src/entities/note.js b/src/entities/note.js
index faabc4714..5e2de26a4 100644
--- a/src/entities/note.js
+++ b/src/entities/note.js
@@ -2,6 +2,7 @@
const Entity = require('./entity');
const Attribute = require('./attribute');
+const NoteContent = require('./note_content');
const protectedSessionService = require('../services/protected_session');
const repository = require('../services/repository');
const sql = require('../services/sql');
@@ -62,6 +63,10 @@ class Note extends Entity {
async getNoteContent() {
if (!this.noteContent) {
this.noteContent = await repository.getEntity(`SELECT * FROM note_contents WHERE noteId = ?`, [this.noteId]);
+
+ if (!this.noteContent) {
+ throw new Error("Note content not found for noteId=" + this.noteId);
+ }
}
return this.noteContent;
@@ -81,6 +86,23 @@ class Note extends Entity {
return JSON.parse(content);
}
+ /** @returns {Promise} */
+ async setContent(content) {
+ if (!this.noteContent) {
+ // make sure it is loaded
+ await this.getNoteContent();
+ }
+
+ this.noteContent.content = content;
+
+ await this.noteContent.save();
+ }
+
+ /** @returns {Promise} */
+ async setJsonContent(content) {
+ await this.setContent(JSON.stringify(content));
+ }
+
/** @returns {boolean} true if this note is the root of the note tree. Root note has "root" noteId */
isRoot() {
return this.noteId === 'root';
@@ -620,9 +642,6 @@ class Note extends Entity {
}
beforeSaving() {
- // we do this here because encryption needs the note ID for the IV
- this.generateIdIfNecessary();
-
if (!this.isDeleted) {
this.isDeleted = false;
}
diff --git a/src/services/attributes.js b/src/services/attributes.js
index 57825d736..c3f431747 100644
--- a/src/services/attributes.js
+++ b/src/services/attributes.js
@@ -100,6 +100,5 @@ module.exports = {
getNoteWithLabel,
createLabel,
createAttribute,
- getAttributeNames,
- BUILTIN_ATTRIBUTES
+ getAttributeNames
};
\ No newline at end of file
diff --git a/src/services/notes.js b/src/services/notes.js
index 9e07260e0..2bd780f76 100644
--- a/src/services/notes.js
+++ b/src/services/notes.js
@@ -96,7 +96,7 @@ async function createNewNote(parentNoteId, noteData) {
note.noteContent = await new NoteContent({
noteId: note.noteId,
content: noteData.content
- });
+ }).save();
const branch = await new Branch({
noteId: note.noteId,