Build your personal knowledge base with Trilium Notes
TypeScript electronelectron-appknowledge-baseknowledge-graphknowledge-managementknowledge-management-graphlocal-firstnote-managmentnote-takernote-takingnotebooknotesnotes-apppersonal-knowledge-basepersonal-wikiscriptableself-hostedself-hostingwiki
note revision sync and other fixes
zadam2e58e32112db
diff --git a/.idea/dataSources/a2c75661-f9e2-478f-a69f-6a9409e69997.xml b/.idea/dataSources/a2c75661-f9e2-478f-a69f-6a9409e69997.xmlindex 22d1652a11..fd55d255c0 100644--- a/.idea/dataSources/a2c75661-f9e2-478f-a69f-6a9409e69997.xml+++ b/.idea/dataSources/a2c75661-f9e2-478f-a69f-6a9409e69997.xml@@ -13,8 +13,8 @@<table id="6" parent="2" name="api_tokens"/><table id="7" parent="2" name="attributes"/><table id="8" parent="2" name="branches"/>- <table id="9" parent="2" name="event_log"/>- <table id="10" parent="2" name="note_contents"/>+ <table id="9" parent="2" name="note_contents"/>+ <table id="10" parent="2" name="note_revision_contents"/><table id="11" parent="2" name="note_revisions"/><table id="12" parent="2" name="notes"/><table id="13" parent="2" name="options"/>@@ -57,6 +57,7 @@<index id="24" parent="6" name="sqlite_autoindex_api_tokens_1"><NameSurrogate>1</NameSurrogate><ColNames>apiTokenId</ColNames>+ <ColumnCollations></ColumnCollations><Unique>1</Unique></index><key id="25" parent="6">@@ -125,20 +126,25 @@<index id="37" parent="7" name="sqlite_autoindex_attributes_1"><NameSurrogate>1</NameSurrogate><ColNames>attributeId</ColNames>+ <ColumnCollations></ColumnCollations><Unique>1</Unique></index><index id="38" parent="7" name="IDX_attributes_noteId_index"><ColNames>noteId</ColNames>+ <ColumnCollations></ColumnCollations></index><index id="39" parent="7" name="IDX_attributes_name_value"><ColNames>namevalue</ColNames>+ <ColumnCollations></ColumnCollations></index><index id="40" parent="7" name="IDX_attributes_name_index"><ColNames>name</ColNames>+ <ColumnCollations></ColumnCollations></index><index id="41" parent="7" name="IDX_attributes_value_index"><ColNames>value</ColNames>+ <ColumnCollations></ColumnCollations></index><key id="42" parent="7"><ColNames>attributeId</ColNames>@@ -171,7 +177,9 @@ value</ColNames></column><column id="48" parent="8" name="isExpanded"><Position>6</Position>- <DataType>BOOLEAN|0s</DataType>+ <DataType>INTEGER|0s</DataType>+ <NotNull>1</NotNull>+ <DefaultExpression>0</DefaultExpression></column><column id="49" parent="8" name="isDeleted"><Position>7</Position>@@ -198,52 +206,60 @@ value</ColNames><index id="53" parent="8" name="sqlite_autoindex_branches_1"><NameSurrogate>1</NameSurrogate><ColNames>branchId</ColNames>+ <ColumnCollations></ColumnCollations><Unique>1</Unique></index><index id="54" parent="8" name="IDX_branches_noteId_parentNoteId"><ColNames>noteIdparentNoteId</ColNames>+ <ColumnCollations></ColumnCollations></index><index id="55" parent="8" name="IDX_branches_noteId"><ColNames>noteId</ColNames>+ <ColumnCollations></ColumnCollations></index><index id="56" parent="8" name="IDX_branches_parentNoteId"><ColNames>parentNoteId</ColNames>+ <ColumnCollations></ColumnCollations></index><key id="57" parent="8"><ColNames>branchId</ColNames><Primary>1</Primary><UnderlyingIndexName>sqlite_autoindex_branches_1</UnderlyingIndexName></key>- <column id="58" parent="9" name="eventId">+ <column id="58" parent="9" name="noteId"><Position>1</Position><DataType>TEXT|0s</DataType><NotNull>1</NotNull></column>- <column id="59" parent="9" name="noteId">+ <column id="59" parent="9" name="content"><Position>2</Position><DataType>TEXT|0s</DataType>+ <DefaultExpression>NULL</DefaultExpression></column>- <column id="60" parent="9" name="comment">+ <column id="60" parent="9" name="hash"><Position>3</Position><DataType>TEXT|0s</DataType>+ <NotNull>1</NotNull>+ <DefaultExpression>""</DefaultExpression></column>- <column id="61" parent="9" name="utcDateCreated">+ <column id="61" parent="9" name="utcDateModified"><Position>4</Position><DataType>TEXT|0s</DataType><NotNull>1</NotNull></column>- <index id="62" parent="9" name="sqlite_autoindex_event_log_1">+ <index id="62" parent="9" name="sqlite_autoindex_note_contents_1"><NameSurrogate>1</NameSurrogate>- <ColNames>eventId</ColNames>+ <ColNames>noteId</ColNames>+ <ColumnCollations></ColumnCollations><Unique>1</Unique></index><key id="63" parent="9">- <ColNames>eventId</ColNames>+ <ColNames>noteId</ColNames><Primary>1</Primary>- <UnderlyingIndexName>sqlite_autoindex_event_log_1</UnderlyingIndexName>+ <UnderlyingIndexName>sqlite_autoindex_note_contents_1</UnderlyingIndexName></key>- <column id="64" parent="10" name="noteId">+ <column id="64" parent="10" name="noteRevisionId"><Position>1</Position><DataType>TEXT|0s</DataType><NotNull>1</NotNull>@@ -251,28 +267,28 @@ parentNoteId</ColNames><column id="65" parent="10" name="content"><Position>2</Position><DataType>TEXT|0s</DataType>- <DefaultExpression>NULL</DefaultExpression></column><column id="66" parent="10" name="hash"><Position>3</Position><DataType>TEXT|0s</DataType><NotNull>1</NotNull>- <DefaultExpression>""</DefaultExpression>+ <DefaultExpression>''</DefaultExpression></column><column id="67" parent="10" name="utcDateModified"><Position>4</Position><DataType>TEXT|0s</DataType><NotNull>1</NotNull></column>- <index id="68" parent="10" name="sqlite_autoindex_note_contents_1">+ <index id="68" parent="10" name="sqlite_autoindex_note_revision_contents_1"><NameSurrogate>1</NameSurrogate>- <ColNames>noteId</ColNames>+ <ColNames>noteRevisionId</ColNames>+ <ColumnCollations></ColumnCollations><Unique>1</Unique></index><key id="69" parent="10">- <ColNames>noteId</ColNames>+ <ColNames>noteRevisionId</ColNames><Primary>1</Primary>- <UnderlyingIndexName>sqlite_autoindex_note_contents_1</UnderlyingIndexName>+ <UnderlyingIndexName>sqlite_autoindex_note_revision_contents_1</UnderlyingIndexName></key><column id="70" parent="11" name="noteRevisionId"><Position>1</Position>@@ -288,9 +304,10 @@ parentNoteId</ColNames><Position>3</Position><DataType>TEXT|0s</DataType></column>- <column id="73" parent="11" name="content">+ <column id="73" parent="11" name="contentLength"><Position>4</Position>- <DataType>TEXT|0s</DataType>+ <DataType>INT|0s</DataType>+ <NotNull>1</NotNull></column><column id="74" parent="11" name="isProtected"><Position>5</Position>@@ -298,291 +315,314 @@ parentNoteId</ColNames><NotNull>1</NotNull><DefaultExpression>0</DefaultExpression></column>- <column id="75" parent="11" name="utcDateModifiedFrom">+ <column id="75" parent="11" name="utcDateLastEdited"><Position>6</Position><DataType>TEXT|0s</DataType><NotNull>1</NotNull></column>- <column id="76" parent="11" name="utcDateModifiedTo">+ <column id="76" parent="11" name="utcDateCreated"><Position>7</Position><DataType>TEXT|0s</DataType><NotNull>1</NotNull></column>- <column id="77" parent="11" name="dateModifiedFrom">+ <column id="77" parent="11" name="utcDateModified"><Position>8</Position><DataType>TEXT|0s</DataType><NotNull>1</NotNull></column>- <column id="78" parent="11" name="dateModifiedTo">+ <column id="78" parent="11" name="dateLastEdited"><Position>9</Position><DataType>TEXT|0s</DataType><NotNull>1</NotNull></column>- <column id="79" parent="11" name="type">+ <column id="79" parent="11" name="dateCreated"><Position>10</Position><DataType>TEXT|0s</DataType><NotNull>1</NotNull>- <DefaultExpression>''</DefaultExpression></column>- <column id="80" parent="11" name="mime">+ <column id="80" parent="11" name="type"><Position>11</Position><DataType>TEXT|0s</DataType><NotNull>1</NotNull><DefaultExpression>''</DefaultExpression></column>- <column id="81" parent="11" name="hash">+ <column id="81" parent="11" name="mime"><Position>12</Position><DataType>TEXT|0s</DataType><NotNull>1</NotNull>- <DefaultExpression>""</DefaultExpression>+ <DefaultExpression>''</DefaultExpression></column>- <index id="82" parent="11" name="sqlite_autoindex_note_revisions_1">+ <column id="82" parent="11" name="hash">+ <Position>13</Position>+ <DataType>TEXT|0s</DataType>+ <NotNull>1</NotNull>+ <DefaultExpression>''</DefaultExpression>+ </column>+ <index id="83" parent="11" name="sqlite_autoindex_note_revisions_1"><NameSurrogate>1</NameSurrogate><ColNames>noteRevisionId</ColNames>+ <ColumnCollations></ColumnCollations><Unique>1</Unique></index>- <index id="83" parent="11" name="IDX_note_revisions_noteId">+ <index id="84" parent="11" name="IDX_note_revisions_noteId"><ColNames>noteId</ColNames>+ <ColumnCollations></ColumnCollations>+ </index>+ <index id="85" parent="11" name="IDX_note_revisions_utcDateLastEdited">+ <ColNames>utcDateLastEdited</ColNames>+ <ColumnCollations></ColumnCollations>+ </index>+ <index id="86" parent="11" name="IDX_note_revisions_utcDateCreated">+ <ColNames>utcDateCreated</ColNames>+ <ColumnCollations></ColumnCollations></index>- <index id="84" parent="11" name="IDX_note_revisions_dateModifiedFrom">- <ColNames>utcDateModifiedFrom</ColNames>+ <index id="87" parent="11" name="IDX_note_revisions_dateLastEdited">+ <ColNames>dateLastEdited</ColNames>+ <ColumnCollations></ColumnCollations></index>- <index id="85" parent="11" name="IDX_note_revisions_dateModifiedTo">- <ColNames>utcDateModifiedTo</ColNames>+ <index id="88" parent="11" name="IDX_note_revisions_dateCreated">+ <ColNames>dateCreated</ColNames>+ <ColumnCollations></ColumnCollations></index>- <key id="86" parent="11">+ <key id="89" parent="11"><ColNames>noteRevisionId</ColNames><Primary>1</Primary><UnderlyingIndexName>sqlite_autoindex_note_revisions_1</UnderlyingIndexName></key>- <column id="87" parent="12" name="noteId">+ <column id="90" parent="12" name="noteId"><Position>1</Position><DataType>TEXT|0s</DataType><NotNull>1</NotNull></column>- <column id="88" parent="12" name="title">+ <column id="91" parent="12" name="title"><Position>2</Position><DataType>TEXT|0s</DataType><NotNull>1</NotNull><DefaultExpression>"note"</DefaultExpression></column>- <column id="89" parent="12" name="isProtected">+ <column id="92" parent="12" name="isProtected"><Position>3</Position><DataType>INT|0s</DataType><NotNull>1</NotNull><DefaultExpression>0</DefaultExpression></column>- <column id="90" parent="12" name="type">+ <column id="93" parent="12" name="type"><Position>4</Position><DataType>TEXT|0s</DataType><NotNull>1</NotNull><DefaultExpression>'text'</DefaultExpression></column>- <column id="91" parent="12" name="mime">+ <column id="94" parent="12" name="mime"><Position>5</Position><DataType>TEXT|0s</DataType><NotNull>1</NotNull><DefaultExpression>'text/html'</DefaultExpression></column>- <column id="92" parent="12" name="hash">+ <column id="95" parent="12" name="hash"><Position>6</Position><DataType>TEXT|0s</DataType><NotNull>1</NotNull><DefaultExpression>""</DefaultExpression></column>- <column id="93" parent="12" name="isDeleted">+ <column id="96" parent="12" name="isDeleted"><Position>7</Position><DataType>INT|0s</DataType><NotNull>1</NotNull><DefaultExpression>0</DefaultExpression></column>- <column id="94" parent="12" name="dateCreated">+ <column id="97" parent="12" name="dateCreated"><Position>8</Position><DataType>TEXT|0s</DataType><NotNull>1</NotNull></column>- <column id="95" parent="12" name="dateModified">+ <column id="98" parent="12" name="dateModified"><Position>9</Position><DataType>TEXT|0s</DataType><NotNull>1</NotNull></column>- <column id="96" parent="12" name="utcDateCreated">+ <column id="99" parent="12" name="utcDateCreated"><Position>10</Position><DataType>TEXT|0s</DataType><NotNull>1</NotNull></column>- <column id="97" parent="12" name="utcDateModified">+ <column id="100" parent="12" name="utcDateModified"><Position>11</Position><DataType>TEXT|0s</DataType><NotNull>1</NotNull></column>- <index id="98" parent="12" name="sqlite_autoindex_notes_1">+ <index id="101" parent="12" name="sqlite_autoindex_notes_1"><NameSurrogate>1</NameSurrogate><ColNames>noteId</ColNames>+ <ColumnCollations></ColumnCollations><Unique>1</Unique></index>- <key id="99" parent="12">+ <key id="102" parent="12"><ColNames>noteId</ColNames><Primary>1</Primary><UnderlyingIndexName>sqlite_autoindex_notes_1</UnderlyingIndexName></key>- <column id="100" parent="13" name="name">+ <column id="103" parent="13" name="name"><Position>1</Position><DataType>TEXT|0s</DataType><NotNull>1</NotNull></column>- <column id="101" parent="13" name="value">+ <column id="104" parent="13" name="value"><Position>2</Position><DataType>TEXT|0s</DataType></column>- <column id="102" parent="13" name="isSynced">+ <column id="105" parent="13" name="isSynced"><Position>3</Position><DataType>INTEGER|0s</DataType><NotNull>1</NotNull><DefaultExpression>0</DefaultExpression></column>- <column id="103" parent="13" name="hash">+ <column id="106" parent="13" name="hash"><Position>4</Position><DataType>TEXT|0s</DataType><NotNull>1</NotNull><DefaultExpression>""</DefaultExpression></column>- <column id="104" parent="13" name="utcDateCreated">+ <column id="107" parent="13" name="utcDateCreated"><Position>5</Position><DataType>TEXT|0s</DataType><NotNull>1</NotNull></column>- <column id="105" parent="13" name="utcDateModified">+ <column id="108" parent="13" name="utcDateModified"><Position>6</Position><DataType>TEXT|0s</DataType><NotNull>1</NotNull></column>- <index id="106" parent="13" name="sqlite_autoindex_options_1">+ <index id="109" parent="13" name="sqlite_autoindex_options_1"><NameSurrogate>1</NameSurrogate><ColNames>name</ColNames>+ <ColumnCollations></ColumnCollations><Unique>1</Unique></index>- <key id="107" parent="13">+ <key id="110" parent="13"><ColNames>name</ColNames><Primary>1</Primary><UnderlyingIndexName>sqlite_autoindex_options_1</UnderlyingIndexName></key>- <column id="108" parent="14" name="noteId">+ <column id="111" parent="14" name="noteId"><Position>1</Position><DataType>TEXT|0s</DataType><NotNull>1</NotNull></column>- <column id="109" parent="14" name="notePath">+ <column id="112" parent="14" name="notePath"><Position>2</Position><DataType>TEXT|0s</DataType><NotNull>1</NotNull></column>- <column id="110" parent="14" name="hash">+ <column id="113" parent="14" name="hash"><Position>3</Position><DataType>TEXT|0s</DataType><NotNull>1</NotNull><DefaultExpression>""</DefaultExpression></column>- <column id="111" parent="14" name="utcDateCreated">+ <column id="114" parent="14" name="utcDateCreated"><Position>4</Position><DataType>TEXT|0s</DataType><NotNull>1</NotNull></column>- <column id="112" parent="14" name="isDeleted">+ <column id="115" parent="14" name="isDeleted"><Position>5</Position><DataType>INT|0s</DataType></column>- <index id="113" parent="14" name="sqlite_autoindex_recent_notes_1">+ <index id="116" parent="14" name="sqlite_autoindex_recent_notes_1"><NameSurrogate>1</NameSurrogate><ColNames>noteId</ColNames>+ <ColumnCollations></ColumnCollations><Unique>1</Unique></index>- <key id="114" parent="14">+ <key id="117" parent="14"><ColNames>noteId</ColNames><Primary>1</Primary><UnderlyingIndexName>sqlite_autoindex_recent_notes_1</UnderlyingIndexName></key>- <column id="115" parent="15" name="sourceId">+ <column id="118" parent="15" name="sourceId"><Position>1</Position><DataType>TEXT|0s</DataType><NotNull>1</NotNull></column>- <column id="116" parent="15" name="utcDateCreated">+ <column id="119" parent="15" name="utcDateCreated"><Position>2</Position><DataType>TEXT|0s</DataType><NotNull>1</NotNull></column>- <index id="117" parent="15" name="sqlite_autoindex_source_ids_1">+ <index id="120" parent="15" name="sqlite_autoindex_source_ids_1"><NameSurrogate>1</NameSurrogate><ColNames>sourceId</ColNames>+ <ColumnCollations></ColumnCollations><Unique>1</Unique></index>- <key id="118" parent="15">+ <key id="121" parent="15"><ColNames>sourceId</ColNames><Primary>1</Primary><UnderlyingIndexName>sqlite_autoindex_source_ids_1</UnderlyingIndexName></key>- <column id="119" parent="16" name="type">+ <column id="122" parent="16" name="type"><Position>1</Position><DataType>text|0s</DataType></column>- <column id="120" parent="16" name="name">+ <column id="123" parent="16" name="name"><Position>2</Position><DataType>text|0s</DataType></column>- <column id="121" parent="16" name="tbl_name">+ <column id="124" parent="16" name="tbl_name"><Position>3</Position><DataType>text|0s</DataType></column>- <column id="122" parent="16" name="rootpage">+ <column id="125" parent="16" name="rootpage"><Position>4</Position><DataType>int|0s</DataType></column>- <column id="123" parent="16" name="sql">+ <column id="126" parent="16" name="sql"><Position>5</Position><DataType>text|0s</DataType></column>- <column id="124" parent="17" name="name">+ <column id="127" parent="17" name="name"><Position>1</Position></column>- <column id="125" parent="17" name="seq">+ <column id="128" parent="17" name="seq"><Position>2</Position></column>- <column id="126" parent="18" name="id">+ <column id="129" parent="18" name="id"><Position>1</Position><DataType>INTEGER|0s</DataType><NotNull>1</NotNull><SequenceIdentity>1</SequenceIdentity></column>- <column id="127" parent="18" name="entityName">+ <column id="130" parent="18" name="entityName"><Position>2</Position><DataType>TEXT|0s</DataType><NotNull>1</NotNull></column>- <column id="128" parent="18" name="entityId">+ <column id="131" parent="18" name="entityId"><Position>3</Position><DataType>TEXT|0s</DataType><NotNull>1</NotNull></column>- <column id="129" parent="18" name="sourceId">+ <column id="132" parent="18" name="sourceId"><Position>4</Position><DataType>TEXT|0s</DataType><NotNull>1</NotNull></column>- <column id="130" parent="18" name="utcSyncDate">+ <column id="133" parent="18" name="utcSyncDate"><Position>5</Position><DataType>TEXT|0s</DataType><NotNull>1</NotNull></column>- <index id="131" parent="18" name="IDX_sync_entityName_entityId">+ <index id="134" parent="18" name="IDX_sync_entityName_entityId"><ColNames>entityNameentityId</ColNames>+ <ColumnCollations></ColumnCollations><Unique>1</Unique></index>- <index id="132" parent="18" name="IDX_sync_utcSyncDate">+ <index id="135" parent="18" name="IDX_sync_utcSyncDate"><ColNames>utcSyncDate</ColNames>+ <ColumnCollations></ColumnCollations></index>- <key id="133" parent="18">+ <key id="136" parent="18"><ColNames>id</ColNames><Primary>1</Primary></key>diff --git a/db/migrations/0150__note_revision_contents.sql b/db/migrations/0150__note_revision_contents.sqlindex 5349f175d2..806eb3586b 100644--- a/db/migrations/0150__note_revision_contents.sql+++ b/db/migrations/0150__note_revision_contents.sql@@ -31,3 +31,6 @@ CREATE INDEX `IDX_note_revisions_utcDateCreated` ON `note_revisions` (`utcDateCrCREATE INDEX `IDX_note_revisions_utcDateLastEdited` ON `note_revisions` (`utcDateLastEdited`);CREATE INDEX `IDX_note_revisions_dateCreated` ON `note_revisions` (`dateCreated`);CREATE INDEX `IDX_note_revisions_dateLastEdited` ON `note_revisions` (`dateLastEdited`);++INSERT INTO sync (entityName, entityId, sourceId, utcSyncDate)+SELECT 'note_revision_contents', entityId, sourceId, utcSyncDate FROM sync WHERE entityName = 'note_revisions';\ No newline at end of filediff --git a/db/schema.sql b/db/schema.sqlindex d649a58701..c13e2bae5c 100644--- a/db/schema.sql+++ b/db/schema.sql@@ -9,19 +9,6 @@ CREATE TABLE IF NOT EXISTS "source_ids" (`utcDateCreated` TEXT NOT NULL,PRIMARY KEY(`sourceId`));-CREATE TABLE IF NOT EXISTS "note_revisions" (- `noteRevisionId` TEXT NOT NULL PRIMARY KEY,- `noteId` TEXT NOT NULL,- `title` TEXT,- `content` TEXT,- `isProtected` INT NOT NULL DEFAULT 0,- `utcDateModifiedFrom` TEXT NOT NULL,- `utcDateModifiedTo` TEXT NOT NULL,- `dateModifiedFrom` TEXT NOT NULL,- `dateModifiedTo` TEXT NOT NULL,- type TEXT DEFAULT '' NOT NULL,- mime TEXT DEFAULT '' NOT NULL,- hash TEXT DEFAULT "" NOT NULL);CREATE TABLE IF NOT EXISTS "api_tokens"(apiTokenId TEXT PRIMARY KEY NOT NULL,@@ -72,15 +59,6 @@ CREATE UNIQUE INDEX `IDX_sync_entityName_entityId` ON `sync` (CREATE INDEX `IDX_sync_utcSyncDate` ON `sync` (`utcSyncDate`);-CREATE INDEX `IDX_note_revisions_noteId` ON `note_revisions` (- `noteId`- );-CREATE INDEX `IDX_note_revisions_dateModifiedFrom` ON `note_revisions` (- `utcDateModifiedFrom`- );-CREATE INDEX `IDX_note_revisions_dateModifiedTo` ON `note_revisions` (- `utcDateModifiedTo`- );CREATE INDEX IDX_attributes_name_valueon attributes (name, value);CREATE INDEX IDX_attributes_name_index@@ -119,3 +97,25 @@ CREATE TABLE IF NOT EXISTS "branches" (CREATE INDEX `IDX_branches_noteId` ON `branches` (`noteId`);CREATE INDEX `IDX_branches_noteId_parentNoteId` ON `branches` (`noteId`,`parentNoteId`);CREATE INDEX IDX_branches_parentNoteId ON branches (parentNoteId);+CREATE TABLE IF NOT EXISTS "note_revisions" (`noteRevisionId` TEXT NOT NULL PRIMARY KEY,+ `noteId` TEXT NOT NULL,+ `title` TEXT,+ `contentLength` INT NOT NULL,+ `isProtected` INT NOT NULL DEFAULT 0,+ `utcDateLastEdited` TEXT NOT NULL,+ `utcDateCreated` TEXT NOT NULL,+ `utcDateModified` TEXT NOT NULL,+ `dateLastEdited` TEXT NOT NULL,+ `dateCreated` TEXT NOT NULL,+ type TEXT DEFAULT '' NOT NULL,+ mime TEXT DEFAULT '' NOT NULL,+ hash TEXT DEFAULT '' NOT NULL);+CREATE TABLE IF NOT EXISTS "note_revision_contents" (`noteRevisionId` TEXT NOT NULL PRIMARY KEY,+ `content` TEXT,+ hash TEXT DEFAULT '' NOT NULL,+ `utcDateModified` TEXT NOT NULL);+CREATE INDEX `IDX_note_revisions_noteId` ON `note_revisions` (`noteId`);+CREATE INDEX `IDX_note_revisions_utcDateCreated` ON `note_revisions` (`utcDateCreated`);+CREATE INDEX `IDX_note_revisions_utcDateLastEdited` ON `note_revisions` (`utcDateLastEdited`);+CREATE INDEX `IDX_note_revisions_dateCreated` ON `note_revisions` (`dateCreated`);+CREATE INDEX `IDX_note_revisions_dateLastEdited` ON `note_revisions` (`dateLastEdited`);diff --git a/src/entities/note_revision.js b/src/entities/note_revision.jsindex 6cd8853e8d..260d748943 100644--- a/src/entities/note_revision.js+++ b/src/entities/note_revision.js@@ -125,7 +125,7 @@ class NoteRevision extends Entity {await sql.upsert("note_revision_contents", "noteRevisionId", pojo);- await syncTableService.addNoteContentSync(this.noteId);+ await syncTableService.addNoteRevisionContentSync(this.noteRevisionId);}// cannot be static!diff --git a/src/public/javascripts/services/note_tooltip.js b/src/public/javascripts/services/note_tooltip.jsindex ac7da96c5c..9edb33b440 100644--- a/src/public/javascripts/services/note_tooltip.js+++ b/src/public/javascripts/services/note_tooltip.js@@ -19,7 +19,9 @@ function setupElementTooltip($el) {async function mouseEnterHandler() {const $link = $(this);- if ($link.hasClass("no-tooltip-preview") || $link.hasClass("disabled")) {+ if ($link.hasClass("no-tooltip-preview")+ || $link.hasClass("disabled")+ || $link.attr("data-action") === 'note-revision') {return;}diff --git a/src/routes/api/note_revisions.js b/src/routes/api/note_revisions.jsindex 5222429701..464d66cf29 100644--- a/src/routes/api/note_revisions.js+++ b/src/routes/api/note_revisions.js@@ -14,11 +14,11 @@ async function getNoteRevisions(req) {}async function getNoteRevision(req) {- const {noteRevisionId} = req.params;+ const noteRevision = await repository.getNoteRevision(req.params.noteRevisionId);- return await repository.getNote(`SELECT *- FROM note_revisions- WHERE noteRevisionId = ?`, [noteId]);+ await noteRevision.getContent();++ return noteRevision;}async function getEditedNotesOnDate(req) {diff --git a/src/services/repository.js b/src/services/repository.jsindex 3d6f3a79b8..38d835f354 100644--- a/src/services/repository.js+++ b/src/services/repository.js@@ -141,6 +141,7 @@ module.exports = {getEntity,getNote,getNotes,+ getNoteRevision,getBranch,getAttribute,getOption,diff --git a/src/services/sync_table.js b/src/services/sync_table.jsindex bb3ace759a..79a20d7fe3 100644--- a/src/services/sync_table.js+++ b/src/services/sync_table.js@@ -64,6 +64,7 @@ async function fillAllSyncRows() {await fillSyncRows("note_contents", "noteId");await fillSyncRows("branches", "branchId");await fillSyncRows("note_revisions", "noteRevisionId");+ await fillSyncRows("note_revision_contents", "noteRevisionId");await fillSyncRows("recent_notes", "noteId");await fillSyncRows("attributes", "attributeId");await fillSyncRows("api_tokens", "apiTokenId");@@ -76,6 +77,7 @@ module.exports = {addBranchSync: async (branchId, sourceId) => await addEntitySync("branches", branchId, sourceId),addNoteReorderingSync: async (parentNoteId, sourceId) => await addEntitySync("note_reordering", parentNoteId, sourceId),addNoteRevisionSync: async (noteRevisionId, sourceId) => await addEntitySync("note_revisions", noteRevisionId, sourceId),+ addNoteRevisionContentSync: async (noteRevisionId, sourceId) => await addEntitySync("note_revision_contents", noteRevisionId, sourceId),addOptionsSync: async (name, sourceId) => await addEntitySync("options", name, sourceId),addRecentNoteSync: async (noteId, sourceId) => await addEntitySync("recent_notes", noteId, sourceId),addAttributeSync: async (attributeId, sourceId) => await addEntitySync("attributes", attributeId, sourceId),diff --git a/src/services/sync_update.js b/src/services/sync_update.jsindex 1a2366618d..283f3628e2 100644--- a/src/services/sync_update.js+++ b/src/services/sync_update.js@@ -39,7 +39,7 @@ async function updateEntity(sync, entity, sourceId) {// currently making exception for protected notes and note revisions because here// the title and content are not available decrypted as listeners would expect- if ((entityName !== 'notes' && entityName !== 'note_revisions') || !entity.isProtected) {+ if (!['notes', 'note_contents', 'note_revisions', 'note_revision_contents'].includes(entityName) || !entity.isProtected) {await eventService.emit(eventService.ENTITY_SYNCED, {entityName,entity@@ -101,11 +101,7 @@ async function updateNoteRevision(entity, sourceId) {const orig = await sql.getRowOrNull("SELECT * FROM note_revisions WHERE noteRevisionId = ?", [entity.noteRevisionId]);await sql.transactional(async () => {- // we update note revision even if date modified to is the same because the only thing which might have changed- // is the protected status (and correnspondingly title and content) which doesn't affect the utcDateCreated- if (orig === null || orig.utcDateCreated <= entity.utcDateCreated) {- entity.content = entity.content === null ? null : Buffer.from(entity.content, 'base64');-+ if (orig === null || orig.utcDateModified < entity.utcDateModified) {await sql.replace('note_revisions', entity);await syncTableService.addNoteRevisionSync(entity.noteRevisionId, sourceId);@@ -115,6 +111,22 @@ async function updateNoteRevision(entity, sourceId) {});}+async function updateNoteRevisionContent(entity, sourceId) {+ const orig = await sql.getRowOrNull("SELECT * FROM note_revision_contents WHERE noteRevisionId = ?", [entity.noteRevisionId]);++ await sql.transactional(async () => {+ if (orig === null || orig.utcDateModified < entity.utcDateModified) {+ entity.content = entity.content === null ? null : Buffer.from(entity.content, 'base64');++ await sql.replace('note_revision_contents', entity);++ await syncTableService.addNoteRevisionContentSync(entity.noteRevisionId, sourceId);++ log.info("Update/sync note revision content " + entity.noteRevisionId);+ }+ });+}+async function updateNoteReordering(entityId, entity, sourceId) {await sql.transactional(async () => {for (const key in entity) {