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
fix recent notes (db & sync version increase)
zadam29828f8e8fcf
diff --git a/db/migrations/0136__update_recent_notes.sql b/db/migrations/0136__update_recent_notes.sqlnew file mode 100644index 0000000000..c3397597f1--- /dev/null+++ b/db/migrations/0136__update_recent_notes.sql@@ -0,0 +1,12 @@+drop table recent_notes;++create table recent_notes+(+ noteId TEXT not null primary key,+ notePath TEXT not null,+ hash TEXT default "" not null,+ utcDateCreated TEXT not null,+ isDeleted INT+);++delete from sync where entityName = 'recent_notes';\ No newline at end of filediff --git a/docs/backend_api/RecentNote.html b/docs/backend_api/RecentNote.htmlindex 7e4fe023e9..0e310241bd 100644--- a/docs/backend_api/RecentNote.html+++ b/docs/backend_api/RecentNote.html@@ -28,7 +28,7 @@<header>- <h2><span class="attribs"><span class="type-signature"></span></span>RecentNote<span class="signature">(branchId, notePath, isDeleted, utcDateModified)</span><span class="type-signature"></span></h2>+ <h2><span class="attribs"><span class="type-signature"></span></span>RecentNote<span class="signature">(noteId, notePath, isDeleted, utcDateModified)</span><span class="type-signature"></span></h2><div class="class-description">RecentNote represents recently visited note.</div>@@ -45,7 +45,7 @@- <h4 class="name" id="RecentNote"><span class="type-signature"></span>new RecentNote<span class="signature">(branchId, notePath, isDeleted, utcDateModified)</span><span class="type-signature"></span></h4>+ <h4 class="name" id="RecentNote"><span class="type-signature"></span>new RecentNote<span class="signature">(noteId, notePath, isDeleted, utcDateModified)</span><span class="type-signature"></span></h4>@@ -85,7 +85,7 @@<tr>- <td class="name"><code>branchId</code></td>+ <td class="name"><code>noteId</code></td><td class="type">diff --git a/docs/backend_api/entities_recent_note.js.html b/docs/backend_api/entities_recent_note.js.htmlindex b8e6177ad6..79e160eb96 100644--- a/docs/backend_api/entities_recent_note.js.html+++ b/docs/backend_api/entities_recent_note.js.html@@ -34,7 +34,7 @@ const dateUtils = require('../services/date_utils');/*** RecentNote represents recently visited note.*- * @param {string} branchId+ * @param {string} noteId* @param {string} notePath* @param {boolean} isDeleted* @param {string} utcDateModified@@ -43,8 +43,8 @@ const dateUtils = require('../services/date_utils');*/class RecentNote extends Entity {static get entityName() { return "recent_notes"; }- static get primaryKeyName() { return "branchId"; }- static get hashedProperties() { return ["branchId", "notePath", "utcDateCreated", "isDeleted"]; }+ static get primaryKeyName() { return "noteId"; }+ static get hashedProperties() { return ["noteId", "notePath", "utcDateCreated", "isDeleted"]; }beforeSaving() {if (!this.isDeleted) {diff --git a/docs/frontend_api/FrontendScriptApi.html b/docs/frontend_api/FrontendScriptApi.htmlindex 2ed05931ca..a7a0842e8d 100644--- a/docs/frontend_api/FrontendScriptApi.html+++ b/docs/frontend_api/FrontendScriptApi.html@@ -461,6 +461,115 @@++<h4 class="name" id="tabContext"><span class="type-signature"></span>tabContext<span class="type-signature"></span></h4>+++++++++++ <h5 class="subsection-title">Properties:</h5>++++<table class="props">+ <thead>+ <tr>+++ <th>Type</th>++++++ <th class="last">Description</th>+ </tr>+ </thead>++ <tbody>+++ <tr>+++ <td class="type">+++<span class="param-type">TabContext</span>+|++<span class="param-type">null</span>++++ </td>++++++ <td class="description last">experimental!</td>+ </tr>+++ </tbody>+</table>+++++<dl class="details">+++++++++++++++++++++++++++ <dt class="tag-source">Source:</dt>+ <dd class="tag-source"><ul class="dummy"><li>+ <a href="services_frontend_script_api.js.html">services/frontend_script_api.js</a>, <a href="services_frontend_script_api.js.html#line33">line 33</a>+ </li></ul></dd>++++++++</dl>+++++++@@ -573,7 +682,7 @@<dt class="tag-source">Source:</dt><dd class="tag-source"><ul class="dummy"><li>- <a href="services_frontend_script_api.js.html">services/frontend_script_api.js</a>, <a href="services_frontend_script_api.js.html#line47">line 47</a>+ <a href="services_frontend_script_api.js.html">services/frontend_script_api.js</a>, <a href="services_frontend_script_api.js.html#line50">line 50</a></li></ul></dd>@@ -726,7 +835,7 @@<dt class="tag-source">Source:</dt><dd class="tag-source"><ul class="dummy"><li>- <a href="services_frontend_script_api.js.html">services/frontend_script_api.js</a>, <a href="services_frontend_script_api.js.html#line39">line 39</a>+ <a href="services_frontend_script_api.js.html">services/frontend_script_api.js</a>, <a href="services_frontend_script_api.js.html#line42">line 42</a></li></ul></dd>@@ -879,7 +988,7 @@<dt class="tag-source">Source:</dt><dd class="tag-source"><ul class="dummy"><li>- <a href="services_frontend_script_api.js.html">services/frontend_script_api.js</a>, <a href="services_frontend_script_api.js.html#line66">line 66</a>+ <a href="services_frontend_script_api.js.html">services/frontend_script_api.js</a>, <a href="services_frontend_script_api.js.html#line69">line 69</a></li></ul></dd>@@ -1057,7 +1166,7 @@<dt class="tag-source">Source:</dt><dd class="tag-source"><ul class="dummy"><li>- <a href="services_frontend_script_api.js.html">services/frontend_script_api.js</a>, <a href="services_frontend_script_api.js.html#line255">line 255</a>+ <a href="services_frontend_script_api.js.html">services/frontend_script_api.js</a>, <a href="services_frontend_script_api.js.html#line258">line 258</a></li></ul></dd>@@ -1188,7 +1297,7 @@<dt class="tag-source">Source:</dt><dd class="tag-source"><ul class="dummy"><li>- <a href="services_frontend_script_api.js.html">services/frontend_script_api.js</a>, <a href="services_frontend_script_api.js.html#line215">line 215</a>+ <a href="services_frontend_script_api.js.html">services/frontend_script_api.js</a>, <a href="services_frontend_script_api.js.html#line218">line 218</a></li></ul></dd>@@ -1292,7 +1401,7 @@<dt class="tag-source">Source:</dt><dd class="tag-source"><ul class="dummy"><li>- <a href="services_frontend_script_api.js.html">services/frontend_script_api.js</a>, <a href="services_frontend_script_api.js.html#line267">line 267</a>+ <a href="services_frontend_script_api.js.html">services/frontend_script_api.js</a>, <a href="services_frontend_script_api.js.html#line264">line 264</a></li></ul></dd>@@ -1348,111 +1457,7 @@- <h4 class="name" id="getActiveNoteContent"><span class="type-signature"></span>getActiveNoteContent<span class="signature">()</span><span class="type-signature"> → {string}</span></h4>-------------------<dl class="details">--------------------------- <dt class="tag-source">Source:</dt>- <dd class="tag-source"><ul class="dummy"><li>- <a href="services_frontend_script_api.js.html">services/frontend_script_api.js</a>, <a href="services_frontend_script_api.js.html#line261">line 261</a>- </li></ul></dd>--------</dl>--------------<h5>Returns:</h5>---<div class="param-desc">- content of active note (loaded into right pane)-</div>----<dl>- <dt>- Type- </dt>- <dd>--<span class="param-type">string</span>--- </dd>-</dl>-------------- <h4 class="name" id="getActiveNotePath"><span class="type-signature"></span>getActiveNotePath<span class="signature">()</span><span class="type-signature"> → {Promise.<string>}</span></h4>+ <h4 class="name" id="getActiveNotePath"><span class="type-signature"></span>getActiveNotePath<span class="signature">()</span><span class="type-signature"> → {Promise.<(string|null)>}</span></h4>@@ -1500,7 +1505,7 @@<dt class="tag-source">Source:</dt><dd class="tag-source"><ul class="dummy"><li>- <a href="services_frontend_script_api.js.html">services/frontend_script_api.js</a>, <a href="services_frontend_script_api.js.html#line273">line 273</a>+ <a href="services_frontend_script_api.js.html">services/frontend_script_api.js</a>, <a href="services_frontend_script_api.js.html#line270">line 270</a></li></ul></dd>@@ -1527,7 +1532,7 @@<div class="param-desc">- returns note path of active note+ returns note path of active note or null if there isn't active note</div>@@ -1538,7 +1543,7 @@</dt><dd>-<span class="param-type">Promise.<string></span>+<span class="param-type">Promise.<(string|null)></span></dd>@@ -1604,7 +1609,7 @@<dt class="tag-source">Source:</dt><dd class="tag-source"><ul class="dummy"><li>- <a href="services_frontend_script_api.js.html">services/frontend_script_api.js</a>, <a href="services_frontend_script_api.js.html#line304">line 304</a>+ <a href="services_frontend_script_api.js.html">services/frontend_script_api.js</a>, <a href="services_frontend_script_api.js.html#line305">line 305</a></li></ul></dd>@@ -1761,7 +1766,7 @@<dt class="tag-source">Source:</dt><dd class="tag-source"><ul class="dummy"><li>- <a href="services_frontend_script_api.js.html">services/frontend_script_api.js</a>, <a href="services_frontend_script_api.js.html#line338">line 338</a>+ <a href="services_frontend_script_api.js.html">services/frontend_script_api.js</a>, <a href="services_frontend_script_api.js.html#line339">line 339</a></li></ul></dd>@@ -1861,7 +1866,7 @@<dt class="tag-source">Source:</dt><dd class="tag-source"><ul class="dummy"><li>- <a href="services_frontend_script_api.js.html">services/frontend_script_api.js</a>, <a href="services_frontend_script_api.js.html#line298">line 298</a>+ <a href="services_frontend_script_api.js.html">services/frontend_script_api.js</a>, <a href="services_frontend_script_api.js.html#line299">line 299</a></li></ul></dd>@@ -1970,7 +1975,7 @@ if some action needs to happen on only one specific instance.<dt class="tag-source">Source:</dt><dd class="tag-source"><ul class="dummy"><li>- <a href="services_frontend_script_api.js.html">services/frontend_script_api.js</a>, <a href="services_frontend_script_api.js.html#line208">line 208</a>+ <a href="services_frontend_script_api.js.html">services/frontend_script_api.js</a>, <a href="services_frontend_script_api.js.html#line211">line 211</a></li></ul></dd>@@ -2123,7 +2128,7 @@ if some action needs to happen on only one specific instance.<dt class="tag-source">Source:</dt><dd class="tag-source"><ul class="dummy"><li>- <a href="services_frontend_script_api.js.html">services/frontend_script_api.js</a>, <a href="services_frontend_script_api.js.html#line347">line 347</a>+ <a href="services_frontend_script_api.js.html">services/frontend_script_api.js</a>, <a href="services_frontend_script_api.js.html#line348">line 348</a></li></ul></dd>@@ -2277,7 +2282,7 @@ if some action needs to happen on only one specific instance.<dt class="tag-source">Source:</dt><dd class="tag-source"><ul class="dummy"><li>- <a href="services_frontend_script_api.js.html">services/frontend_script_api.js</a>, <a href="services_frontend_script_api.js.html#line176">line 176</a>+ <a href="services_frontend_script_api.js.html">services/frontend_script_api.js</a>, <a href="services_frontend_script_api.js.html#line179">line 179</a></li></ul></dd>@@ -2476,7 +2481,7 @@ otherwise (by e.g. createNoteLink())<dt class="tag-source">Source:</dt><dd class="tag-source"><ul class="dummy"><li>- <a href="services_frontend_script_api.js.html">services/frontend_script_api.js</a>, <a href="services_frontend_script_api.js.html#line188">line 188</a>+ <a href="services_frontend_script_api.js.html">services/frontend_script_api.js</a>, <a href="services_frontend_script_api.js.html#line191">line 191</a></li></ul></dd>@@ -2580,7 +2585,7 @@ otherwise (by e.g. createNoteLink())<dt class="tag-source">Source:</dt><dd class="tag-source"><ul class="dummy"><li>- <a href="services_frontend_script_api.js.html">services/frontend_script_api.js</a>, <a href="services_frontend_script_api.js.html#line329">line 329</a>+ <a href="services_frontend_script_api.js.html">services/frontend_script_api.js</a>, <a href="services_frontend_script_api.js.html#line330">line 330</a></li></ul></dd>@@ -2733,7 +2738,7 @@ otherwise (by e.g. createNoteLink())<dt class="tag-source">Source:</dt><dd class="tag-source"><ul class="dummy"><li>- <a href="services_frontend_script_api.js.html">services/frontend_script_api.js</a>, <a href="services_frontend_script_api.js.html#line356">line 356</a>+ <a href="services_frontend_script_api.js.html">services/frontend_script_api.js</a>, <a href="services_frontend_script_api.js.html#line357">line 357</a></li></ul></dd>@@ -2840,7 +2845,7 @@ note.<dt class="tag-source">Source:</dt><dd class="tag-source"><ul class="dummy"><li>- <a href="services_frontend_script_api.js.html">services/frontend_script_api.js</a>, <a href="services_frontend_script_api.js.html#line284">line 284</a>+ <a href="services_frontend_script_api.js.html">services/frontend_script_api.js</a>, <a href="services_frontend_script_api.js.html#line285">line 285</a></li></ul></dd>@@ -2993,7 +2998,7 @@ note.<dt class="tag-source">Source:</dt><dd class="tag-source"><ul class="dummy"><li>- <a href="services_frontend_script_api.js.html">services/frontend_script_api.js</a>, <a href="services_frontend_script_api.js.html#line292">line 292</a>+ <a href="services_frontend_script_api.js.html">services/frontend_script_api.js</a>, <a href="services_frontend_script_api.js.html#line293">line 293</a></li></ul></dd>@@ -3124,7 +3129,7 @@ note.<dt class="tag-source">Source:</dt><dd class="tag-source"><ul class="dummy"><li>- <a href="services_frontend_script_api.js.html">services/frontend_script_api.js</a>, <a href="services_frontend_script_api.js.html#line222">line 222</a>+ <a href="services_frontend_script_api.js.html">services/frontend_script_api.js</a>, <a href="services_frontend_script_api.js.html#line225">line 225</a></li></ul></dd>@@ -3228,7 +3233,7 @@ note.<dt class="tag-source">Source:</dt><dd class="tag-source"><ul class="dummy"><li>- <a href="services_frontend_script_api.js.html">services/frontend_script_api.js</a>, <a href="services_frontend_script_api.js.html#line321">line 321</a>+ <a href="services_frontend_script_api.js.html">services/frontend_script_api.js</a>, <a href="services_frontend_script_api.js.html#line322">line 322</a></li></ul></dd>@@ -3314,7 +3319,7 @@ note.<dt class="tag-source">Source:</dt><dd class="tag-source"><ul class="dummy"><li>- <a href="services_frontend_script_api.js.html">services/frontend_script_api.js</a>, <a href="services_frontend_script_api.js.html#line246">line 246</a>+ <a href="services_frontend_script_api.js.html">services/frontend_script_api.js</a>, <a href="services_frontend_script_api.js.html#line249">line 249</a></li></ul></dd>@@ -3463,7 +3468,7 @@ note.<dt class="tag-source">Source:</dt><dd class="tag-source"><ul class="dummy"><li>- <a href="services_frontend_script_api.js.html">services/frontend_script_api.js</a>, <a href="services_frontend_script_api.js.html#line194">line 194</a>+ <a href="services_frontend_script_api.js.html">services/frontend_script_api.js</a>, <a href="services_frontend_script_api.js.html#line197">line 197</a></li></ul></dd>@@ -3594,7 +3599,7 @@ note.<dt class="tag-source">Source:</dt><dd class="tag-source"><ul class="dummy"><li>- <a href="services_frontend_script_api.js.html">services/frontend_script_api.js</a>, <a href="services_frontend_script_api.js.html#line200">line 200</a>+ <a href="services_frontend_script_api.js.html">services/frontend_script_api.js</a>, <a href="services_frontend_script_api.js.html#line203">line 203</a></li></ul></dd>@@ -3753,7 +3758,7 @@ Internally this serializes the anonymous function into string and sends it to ba<dt class="tag-source">Source:</dt><dd class="tag-source"><ul class="dummy"><li>- <a href="services_frontend_script_api.js.html">services/frontend_script_api.js</a>, <a href="services_frontend_script_api.js.html#line116">line 116</a>+ <a href="services_frontend_script_api.js.html">services/frontend_script_api.js</a>, <a href="services_frontend_script_api.js.html#line119">line 119</a></li></ul></dd>@@ -3911,7 +3916,7 @@ Internally this serializes the anonymous function into string and sends it to ba<dt class="tag-source">Source:</dt><dd class="tag-source"><ul class="dummy"><li>- <a href="services_frontend_script_api.js.html">services/frontend_script_api.js</a>, <a href="services_frontend_script_api.js.html#line164">line 164</a>+ <a href="services_frontend_script_api.js.html">services/frontend_script_api.js</a>, <a href="services_frontend_script_api.js.html#line167">line 167</a></li></ul></dd>@@ -4065,7 +4070,7 @@ Internally this serializes the anonymous function into string and sends it to ba<dt class="tag-source">Source:</dt><dd class="tag-source"><ul class="dummy"><li>- <a href="services_frontend_script_api.js.html">services/frontend_script_api.js</a>, <a href="services_frontend_script_api.js.html#line146">line 146</a>+ <a href="services_frontend_script_api.js.html">services/frontend_script_api.js</a>, <a href="services_frontend_script_api.js.html#line149">line 149</a></li></ul></dd>@@ -4214,7 +4219,7 @@ Internally this serializes the anonymous function into string and sends it to ba<dt class="tag-source">Source:</dt><dd class="tag-source"><ul class="dummy"><li>- <a href="services_frontend_script_api.js.html">services/frontend_script_api.js</a>, <a href="services_frontend_script_api.js.html#line310">line 310</a>+ <a href="services_frontend_script_api.js.html">services/frontend_script_api.js</a>, <a href="services_frontend_script_api.js.html#line311">line 311</a></li></ul></dd>@@ -4345,7 +4350,7 @@ Internally this serializes the anonymous function into string and sends it to ba<dt class="tag-source">Source:</dt><dd class="tag-source"><ul class="dummy"><li>- <a href="services_frontend_script_api.js.html">services/frontend_script_api.js</a>, <a href="services_frontend_script_api.js.html#line316">line 316</a>+ <a href="services_frontend_script_api.js.html">services/frontend_script_api.js</a>, <a href="services_frontend_script_api.js.html#line317">line 317</a></li></ul></dd>@@ -4480,7 +4485,7 @@ Internally this serializes the anonymous function into string and sends it to ba<dt class="tag-source">Source:</dt><dd class="tag-source"><ul class="dummy"><li>- <a href="services_frontend_script_api.js.html">services/frontend_script_api.js</a>, <a href="services_frontend_script_api.js.html#line238">line 238</a>+ <a href="services_frontend_script_api.js.html">services/frontend_script_api.js</a>, <a href="services_frontend_script_api.js.html#line241">line 241</a></li></ul></dd>@@ -4615,7 +4620,7 @@ Internally this serializes the anonymous function into string and sends it to ba<dt class="tag-source">Source:</dt><dd class="tag-source"><ul class="dummy"><li>- <a href="services_frontend_script_api.js.html">services/frontend_script_api.js</a>, <a href="services_frontend_script_api.js.html#line230">line 230</a>+ <a href="services_frontend_script_api.js.html">services/frontend_script_api.js</a>, <a href="services_frontend_script_api.js.html#line233">line 233</a></li></ul></dd>diff --git a/docs/frontend_api/global.html b/docs/frontend_api/global.htmlindex 104db4601a..636c6101df 100644--- a/docs/frontend_api/global.html+++ b/docs/frontend_api/global.html@@ -303,7 +303,7 @@<dt class="tag-source">Source:</dt><dd class="tag-source"><ul class="dummy"><li>- <a href="services_frontend_script_api.js.html">services/frontend_script_api.js</a>, <a href="services_frontend_script_api.js.html#line53">line 53</a>+ <a href="services_frontend_script_api.js.html">services/frontend_script_api.js</a>, <a href="services_frontend_script_api.js.html#line56">line 56</a></li></ul></dd>diff --git a/docs/frontend_api/services_frontend_script_api.js.html b/docs/frontend_api/services_frontend_script_api.js.htmlindex be54b8405d..62ff12f087 100644--- a/docs/frontend_api/services_frontend_script_api.js.html+++ b/docs/frontend_api/services_frontend_script_api.js.html@@ -44,7 +44,7 @@ import dateNotesService from'./date_notes.js';* @constructor* @hideconstructor*/-function FrontendScriptApi(startNote, currentNote, originEntity = null) {+function FrontendScriptApi(startNote, currentNote, originEntity = null, tabContext = null) {const $pluginButtons = $("#plugin-buttons");/** @property {object} note where script started executing */@@ -57,6 +57,9 @@ function FrontendScriptApi(startNote, currentNote, originEntity = null) {// to keep consistency with backend APIthis.dayjs = dayjs;+ /** @property {TabContext|null} - experimental! */+ this.tabContext = tabContext;+/*** Activates note in the tree and in the note detail.*@@ -282,12 +285,6 @@ function FrontendScriptApi(startNote, currentNote, originEntity = null) {*/this.createNoteLink = linkService.createNoteLink;- /**- * @method- * @returns {string} content of active note (loaded into right pane)- */- this.getActiveNoteContent = noteDetailService.getActiveNoteContent;-/*** @method* @returns {NoteFull} active note (loaded into right pane)@@ -296,9 +293,13 @@ function FrontendScriptApi(startNote, currentNote, originEntity = null) {/*** @method- * @returns {Promise<string>} returns note path of active note+ * @returns {Promise<string|null>} returns note path of active note or null if there isn't active note*/- this.getActiveNotePath = treeService.getActiveNotePath;+ this.getActiveNotePath = () => {+ const activeTabContext = noteDetailService.getActiveTabContext();++ return activeTabContext ? activeTabContext.notePath : null;+ };/*** This method checks whether user navigated away from the note from which the scripts has been started.diff --git a/src/entities/recent_note.js b/src/entities/recent_note.jsindex fd58894d4a..eab6cb77af 100644--- a/src/entities/recent_note.js+++ b/src/entities/recent_note.js@@ -6,7 +6,7 @@ const dateUtils = require('../services/date_utils');/*** RecentNote represents recently visited note.*- * @param {string} branchId+ * @param {string} noteId* @param {string} notePath* @param {boolean} isDeleted* @param {string} utcDateModified@@ -15,8 +15,8 @@ const dateUtils = require('../services/date_utils');*/class RecentNote extends Entity {static get entityName() { return "recent_notes"; }- static get primaryKeyName() { return "branchId"; }- static get hashedProperties() { return ["branchId", "notePath", "utcDateCreated", "isDeleted"]; }+ static get primaryKeyName() { return "noteId"; }+ static get hashedProperties() { return ["noteId", "notePath", "utcDateCreated", "isDeleted"]; }beforeSaving() {if (!this.isDeleted) {diff --git a/src/public/javascripts/services/tab_context.js b/src/public/javascripts/services/tab_context.jsindex c751e246c1..4a8f45b656 100644--- a/src/public/javascripts/services/tab_context.js+++ b/src/public/javascripts/services/tab_context.js@@ -94,6 +94,7 @@ class TabContext {this.attributes.invalidateAttributes();+ this.$noteTitleRow.show(); // might be hidden from empty detailthis.$tabContent.toggleClass("protected", this.note.isProtected);this.$protectButton.toggleClass("active", this.note.isProtected);this.$protectButton.prop("disabled", this.note.isProtected);@@ -106,8 +107,11 @@ class TabContext {setTimeout(async () => {// we include the note into recent list only if the user stayed on the note at least 5 seconds- if (notePath && notePath === await this.notePath) {- await server.post('recent-notes', { notePath });+ if (notePath && notePath === this.notePath) {+ await server.post('recent-notes', {+ noteId: this.noteId,+ notePath: this.notePath+ });}}, 5000);diff --git a/src/routes/api/autocomplete.js b/src/routes/api/autocomplete.jsindex 5b7d326aee..4e9e4e5bab 100644--- a/src/routes/api/autocomplete.js+++ b/src/routes/api/autocomplete.js@@ -43,11 +43,11 @@ async function getRecentNotes(activeNoteId) {recent_notes.*FROMrecent_notes- JOIN branches USING(branchId)+ JOIN notes USING(noteId)WHERErecent_notes.isDeleted = 0- AND branches.isDeleted = 0- AND branches.noteId != ?+ AND notes.isDeleted = 0+ AND notes.noteId != ?${extraCondition}ORDER BYutcDateCreated DESCdiff --git a/src/routes/api/recent_notes.js b/src/routes/api/recent_notes.jsindex 280dadbad5..4363679641 100644--- a/src/routes/api/recent_notes.js+++ b/src/routes/api/recent_notes.js@@ -3,12 +3,9 @@const RecentNote = require('../../entities/recent_note');async function addRecentNote(req) {- const branchId = req.body.branchId;- const notePath = req.body.notePath;-await new RecentNote({- branchId: branchId,- notePath: notePath+ noteId: req.body.noteId,+ notePath: req.body.notePath}).save();}diff --git a/src/routes/api/sync.js b/src/routes/api/sync.jsindex f77786548b..48a4f1e5bb 100644--- a/src/routes/api/sync.js+++ b/src/routes/api/sync.js@@ -78,13 +78,14 @@ async function forceNoteSync(req) {for (const branchId of await sql.getColumn("SELECT branchId FROM branches WHERE isDeleted = 0 AND noteId = ?", [noteId])) {await syncTableService.addBranchSync(branchId);- await syncTableService.addRecentNoteSync(branchId);}for (const noteRevisionId of await sql.getColumn("SELECT noteRevisionId FROM note_revisions WHERE noteId = ?", [noteId])) {await syncTableService.addNoteRevisionSync(noteRevisionId);}+ await syncTableService.addRecentNoteSync(noteId);+log.info("Forcing note sync for " + noteId);// not awaiting for the job to finish (will probably take a long time)diff --git a/src/services/app_info.js b/src/services/app_info.jsindex 3d44435831..2787ba67c0 100644--- a/src/services/app_info.js+++ b/src/services/app_info.js@@ -4,8 +4,8 @@ const build = require('./build');const packageJson = require('../../package');const {TRILIUM_DATA_DIR} = require('./data_dir');-const APP_DB_VERSION = 135;-const SYNC_VERSION = 8;+const APP_DB_VERSION = 136;+const SYNC_VERSION = 9;module.exports = {appVersion: packageJson.version,diff --git a/src/services/consistency_checks.js b/src/services/consistency_checks.jsindex b09544d5ee..e326264fab 100644--- a/src/services/consistency_checks.js+++ b/src/services/consistency_checks.js@@ -396,7 +396,7 @@ async function findSyncRowsIssues() {await runSyncRowChecks("note_contents", "noteId");await runSyncRowChecks("note_revisions", "noteRevisionId");await runSyncRowChecks("branches", "branchId");- await runSyncRowChecks("recent_notes", "branchId");+ await runSyncRowChecks("recent_notes", "noteId");await runSyncRowChecks("attributes", "attributeId");await runSyncRowChecks("api_tokens", "apiTokenId");await runSyncRowChecks("options", "name");diff --git a/src/services/sync.js b/src/services/sync.jsindex 14b950fa5d..28cfdc3af6 100644--- a/src/services/sync.js+++ b/src/services/sync.js@@ -246,7 +246,7 @@ const primaryKeys = {"note_contents": "noteId","branches": "branchId","note_revisions": "noteRevisionId",- "recent_notes": "branchId",+ "recent_notes": "noteId","api_tokens": "apiTokenId","options": "name","attributes": "attributeId",diff --git a/src/services/sync_table.js b/src/services/sync_table.jsindex 050815111f..4ac6b59726 100644--- a/src/services/sync_table.js+++ b/src/services/sync_table.js@@ -28,8 +28,8 @@ async function addOptionsSync(name, sourceId) {await addEntitySync("options", name, sourceId);}-async function addRecentNoteSync(branchId, sourceId) {- await addEntitySync("recent_notes", branchId, sourceId);+async function addRecentNoteSync(noteId, sourceId) {+ await addEntitySync("recent_notes", noteId, sourceId);}async function addLinkSync(linkId, sourceId) {@@ -91,7 +91,7 @@ async function fillAllSyncRows() {await fillSyncRows("note_contents", "noteId");await fillSyncRows("branches", "branchId");await fillSyncRows("note_revisions", "noteRevisionId");- await fillSyncRows("recent_notes", "branchId");+ await fillSyncRows("recent_notes", "noteId");await fillSyncRows("attributes", "attributeId");await fillSyncRows("api_tokens", "apiTokenId");await fillSyncRows("links", "linkId");diff --git a/src/services/sync_update.js b/src/services/sync_update.jsindex 34a4659fc7..548675357e 100644--- a/src/services/sync_update.js+++ b/src/services/sync_update.js@@ -148,13 +148,13 @@ async function updateOptions(entity, sourceId) {}async function updateRecentNotes(entity, sourceId) {- const orig = await sql.getRowOrNull("SELECT * FROM recent_notes WHERE branchId = ?", [entity.branchId]);+ const orig = await sql.getRowOrNull("SELECT * FROM recent_notes WHERE noteId = ?", [entity.noteId]);if (orig === null || orig.utcDateCreated < entity.utcDateCreated) {await sql.transactional(async () => {await sql.replace('recent_notes', entity);- await syncTableService.addRecentNoteSync(entity.branchId, sourceId);+ await syncTableService.addRecentNoteSync(entity.noteId, sourceId);});}}