diff --git a/db/migrations/0076__add_attribute_name_index.sql b/db/migrations/0076__add_attribute_name_index.sql new file mode 100644 index 000000000..6911a3f2c --- /dev/null +++ b/db/migrations/0076__add_attribute_name_index.sql @@ -0,0 +1 @@ +CREATE INDEX IDX_attributes_name_value ON attributes (name, value); \ No newline at end of file diff --git a/db/schema.sql b/db/schema.sql index 58d07f99b..12cd0c9e6 100644 --- a/db/schema.sql +++ b/db/schema.sql @@ -120,6 +120,7 @@ CREATE INDEX IDX_note_images_noteId ON note_images (noteId); CREATE INDEX IDX_note_images_imageId ON note_images (imageId); CREATE INDEX IDX_note_images_noteId_imageId ON note_images (noteId, imageId); CREATE INDEX IDX_attributes_noteId ON attributes (noteId); +CREATE INDEX IDX_attributes_name_value ON attributes (name, value); CREATE TABLE IF NOT EXISTS "api_tokens" ( diff --git a/src/public/javascripts/note_tree.js b/src/public/javascripts/note_tree.js index e2a4bf3ba..749867d3a 100644 --- a/src/public/javascripts/note_tree.js +++ b/src/public/javascripts/note_tree.js @@ -14,6 +14,8 @@ const noteTree = (function() { let parentChildToNoteTreeId = {}; let noteIdToTitle = {}; + let hiddenInAutocomplete = {}; + function getNoteTreeId(parentNoteId, childNoteId) { assertArguments(parentNoteId, childNoteId); @@ -648,6 +650,12 @@ const noteTree = (function() { startNotePath = getNotePathFromAddress(); } + hiddenInAutocomplete = {}; + + for (const noteId of resp.hiddenInAutocomplete) { + hiddenInAutocomplete[noteId] = true; + } + return prepareNoteTree(resp.notes); } @@ -705,6 +713,10 @@ const noteTree = (function() { const autocompleteItems = []; for (const childNoteId of parentToChildren[parentNoteId]) { + if (hiddenInAutocomplete[childNoteId]) { + continue; + } + const childNotePath = (notePath ? (notePath + '/') : '') + childNoteId; const childTitlePath = (titlePath ? (titlePath + ' / ') : '') + getNoteTitle(childNoteId, parentNoteId); diff --git a/src/routes/api/tree.js b/src/routes/api/tree.js index b78ee096c..e9db493ab 100644 --- a/src/routes/api/tree.js +++ b/src/routes/api/tree.js @@ -29,8 +29,20 @@ router.get('/', auth.checkApiAuth, wrap(async (req, res, next) => { protected_session.decryptNotes(req, notes); + const hiddenInAutocomplete = await sql.getColumn(` + SELECT + DISTINCT noteId + FROM + attributes + JOIN notes USING(noteId) + WHERE + attributes.name = 'hide_in_autocomplete' + AND attributes.isDeleted = 0 + AND notes.isDeleted = 0`); + res.send({ notes: notes, + hiddenInAutocomplete: hiddenInAutocomplete, start_note_path: await options.getOption('start_note_path') }); })); diff --git a/src/services/app_info.js b/src/services/app_info.js index dfac4ab37..86f357af0 100644 --- a/src/services/app_info.js +++ b/src/services/app_info.js @@ -3,7 +3,7 @@ const build = require('./build'); const packageJson = require('../../package'); -const APP_DB_VERSION = 75; +const APP_DB_VERSION = 76; module.exports = { app_version: packageJson.version, diff --git a/src/services/attributes.js b/src/services/attributes.js index eb256599a..12f19bba5 100644 --- a/src/services/attributes.js +++ b/src/services/attributes.js @@ -5,7 +5,12 @@ const utils = require('./utils'); const sync_table = require('./sync_table'); const Repository = require('./repository'); -const BUILTIN_ATTRIBUTES = [ 'run_on_startup', 'disable_versioning', 'calendar_root' ]; +const BUILTIN_ATTRIBUTES = [ + 'run_on_startup', + 'disable_versioning', + 'calendar_root', + 'hide_in_autocomplete' +]; async function getNoteAttributeMap(noteId) { return await sql.getMap(`SELECT name, value FROM attributes WHERE noteId = ?`, [noteId]);