mirror of
				https://github.com/zadam/trilium.git
				synced 2025-10-31 10:26:08 +01:00 
			
		
		
		
	renamed noteCache into becca
This commit is contained in:
		| @@ -411,7 +411,7 @@ class Note extends Entity { | |||||||
|                 return false; |                 return false; | ||||||
|             } |             } | ||||||
|  |  | ||||||
|             // FIXME: this code is quite questionable, one problem is that other caches (Froca, NoteCache) have nothing like that |             // FIXME: this code is quite questionable, one problem is that other caches (Froca, Becca) have nothing like that | ||||||
|             if (attr.isDefinition()) { |             if (attr.isDefinition()) { | ||||||
|                 const firstDefinitionIndex = attributes.findIndex(el => el.type === attr.type && el.name === attr.name); |                 const firstDefinitionIndex = attributes.findIndex(el => el.type === attr.type && el.name === attr.name); | ||||||
|  |  | ||||||
|   | |||||||
| @@ -1,13 +1,13 @@ | |||||||
| const Note = require('../../src/services/note_cache/entities/note.js'); | const Note = require('../../src/services/note_cache/entities/note.js'); | ||||||
| const Branch = require('../../src/services/note_cache/entities/branch.js'); | const Branch = require('../../src/services/note_cache/entities/branch.js'); | ||||||
| const Attribute = require('../../src/services/note_cache/entities/attribute.js'); | const Attribute = require('../../src/services/note_cache/entities/attribute.js'); | ||||||
| const noteCache = require('../../src/services/note_cache/note_cache.js'); | const becca = require('../../src/services/note_cache/note_cache.js'); | ||||||
| const randtoken = require('rand-token').generator({source: 'crypto'}); | const randtoken = require('rand-token').generator({source: 'crypto'}); | ||||||
|  |  | ||||||
| /** @return {Note} */ | /** @return {Note} */ | ||||||
| function findNoteByTitle(searchResults, title) { | function findNoteByTitle(searchResults, title) { | ||||||
|     return searchResults |     return searchResults | ||||||
|         .map(sr => noteCache.notes[sr.noteId]) |         .map(sr => becca.notes[sr.noteId]) | ||||||
|         .find(note => note.title === title); |         .find(note => note.title === title); | ||||||
| } | } | ||||||
|  |  | ||||||
| @@ -17,7 +17,7 @@ class NoteBuilder { | |||||||
|     } |     } | ||||||
|  |  | ||||||
|     label(name, value = '', isInheritable = false) { |     label(name, value = '', isInheritable = false) { | ||||||
|         new Attribute(noteCache, { |         new Attribute(becca, { | ||||||
|             attributeId: id(), |             attributeId: id(), | ||||||
|             noteId: this.note.noteId, |             noteId: this.note.noteId, | ||||||
|             type: 'label', |             type: 'label', | ||||||
| @@ -30,7 +30,7 @@ class NoteBuilder { | |||||||
|     } |     } | ||||||
|  |  | ||||||
|     relation(name, targetNote) { |     relation(name, targetNote) { | ||||||
|         new Attribute(noteCache, { |         new Attribute(becca, { | ||||||
|             attributeId: id(), |             attributeId: id(), | ||||||
|             noteId: this.note.noteId, |             noteId: this.note.noteId, | ||||||
|             type: 'relation', |             type: 'relation', | ||||||
| @@ -42,7 +42,7 @@ class NoteBuilder { | |||||||
|     } |     } | ||||||
|  |  | ||||||
|     child(childNoteBuilder, prefix = "") { |     child(childNoteBuilder, prefix = "") { | ||||||
|         new Branch(noteCache, { |         new Branch(becca, { | ||||||
|             branchId: id(), |             branchId: id(), | ||||||
|             noteId: childNoteBuilder.note.noteId, |             noteId: childNoteBuilder.note.noteId, | ||||||
|             parentNoteId: this.note.noteId, |             parentNoteId: this.note.noteId, | ||||||
| @@ -66,7 +66,7 @@ function note(title, extraParams = {}) { | |||||||
|         mime: 'text/html' |         mime: 'text/html' | ||||||
|     }, extraParams); |     }, extraParams); | ||||||
|  |  | ||||||
|     const note = new Note(noteCache, row); |     const note = new Note(becca, row); | ||||||
|  |  | ||||||
|     return new NoteBuilder(note); |     return new NoteBuilder(note); | ||||||
| } | } | ||||||
|   | |||||||
| @@ -37,7 +37,7 @@ describe("Parser", () => { | |||||||
|         expect(rootExp.constructor.name).toEqual("AndExp"); |         expect(rootExp.constructor.name).toEqual("AndExp"); | ||||||
|         expect(rootExp.subExpressions[0].constructor.name).toEqual("PropertyComparisonExp"); |         expect(rootExp.subExpressions[0].constructor.name).toEqual("PropertyComparisonExp"); | ||||||
|         expect(rootExp.subExpressions[1].constructor.name).toEqual("OrExp"); |         expect(rootExp.subExpressions[1].constructor.name).toEqual("OrExp"); | ||||||
|         expect(rootExp.subExpressions[1].subExpressions[0].constructor.name).toEqual("NoteCacheFlatTextExp"); |         expect(rootExp.subExpressions[1].subExpressions[0].constructor.name).toEqual("BeccaFlatTextExp"); | ||||||
|         expect(rootExp.subExpressions[1].subExpressions[0].tokens).toEqual(["hello", "hi"]); |         expect(rootExp.subExpressions[1].subExpressions[0].tokens).toEqual(["hello", "hi"]); | ||||||
|     }); |     }); | ||||||
|  |  | ||||||
| @@ -55,7 +55,7 @@ describe("Parser", () => { | |||||||
|  |  | ||||||
|         const subs = rootExp.subExpressions[1].subExpressions; |         const subs = rootExp.subExpressions[1].subExpressions; | ||||||
|  |  | ||||||
|         expect(subs[0].constructor.name).toEqual("NoteCacheFlatTextExp"); |         expect(subs[0].constructor.name).toEqual("BeccaFlatTextExp"); | ||||||
|         expect(subs[0].tokens).toEqual(["hello", "hi"]); |         expect(subs[0].tokens).toEqual(["hello", "hi"]); | ||||||
|  |  | ||||||
|         expect(subs[1].constructor.name).toEqual("NoteContentProtectedFulltextExp"); |         expect(subs[1].constructor.name).toEqual("NoteContentProtectedFulltextExp"); | ||||||
| @@ -182,7 +182,7 @@ describe("Parser", () => { | |||||||
|         expect(firstSub.propertyName).toEqual('isArchived'); |         expect(firstSub.propertyName).toEqual('isArchived'); | ||||||
|  |  | ||||||
|         expect(secondSub.constructor.name).toEqual("OrExp"); |         expect(secondSub.constructor.name).toEqual("OrExp"); | ||||||
|         expect(secondSub.subExpressions[0].constructor.name).toEqual("NoteCacheFlatTextExp"); |         expect(secondSub.subExpressions[0].constructor.name).toEqual("BeccaFlatTextExp"); | ||||||
|         expect(secondSub.subExpressions[0].tokens).toEqual(["hello"]); |         expect(secondSub.subExpressions[0].tokens).toEqual(["hello"]); | ||||||
|  |  | ||||||
|         expect(thirdSub.constructor.name).toEqual("LabelComparisonExp"); |         expect(thirdSub.constructor.name).toEqual("LabelComparisonExp"); | ||||||
|   | |||||||
| @@ -3,17 +3,17 @@ const Note = require('../../src/services/note_cache/entities/note.js'); | |||||||
| const Branch = require('../../src/services/note_cache/entities/branch.js'); | const Branch = require('../../src/services/note_cache/entities/branch.js'); | ||||||
| const SearchContext = require('../../src/services/search/search_context.js'); | const SearchContext = require('../../src/services/search/search_context.js'); | ||||||
| const dateUtils = require('../../src/services/date_utils.js'); | const dateUtils = require('../../src/services/date_utils.js'); | ||||||
| const noteCache = require('../../src/services/note_cache/note_cache.js'); | const becca = require('../../src/services/note_cache/note_cache.js'); | ||||||
| const {NoteBuilder, findNoteByTitle, note} = require('./note_cache_mocking.js'); | const {NoteBuilder, findNoteByTitle, note} = require('./note_cache_mocking.js'); | ||||||
|  |  | ||||||
| describe("Search", () => { | describe("Search", () => { | ||||||
|     let rootNote; |     let rootNote; | ||||||
|  |  | ||||||
|     beforeEach(() => { |     beforeEach(() => { | ||||||
|         noteCache.reset(); |         becca.reset(); | ||||||
|  |  | ||||||
|         rootNote = new NoteBuilder(new Note(noteCache, {noteId: 'root', title: 'root', type: 'text'})); |         rootNote = new NoteBuilder(new Note(becca, {noteId: 'root', title: 'root', type: 'text'})); | ||||||
|         new Branch(noteCache, {branchId: 'root', noteId: 'root', parentNoteId: 'none', notePosition: 10}); |         new Branch(becca, {branchId: 'root', noteId: 'root', parentNoteId: 'none', notePosition: 10}); | ||||||
|     }); |     }); | ||||||
|  |  | ||||||
|     it("simple path match", () => { |     it("simple path match", () => { | ||||||
| @@ -538,29 +538,29 @@ describe("Search", () => { | |||||||
|  |  | ||||||
|         let searchResults = searchService.findNotesWithQuery('# note.parents.title = Europe orderBy note.title', searchContext); |         let searchResults = searchService.findNotesWithQuery('# note.parents.title = Europe orderBy note.title', searchContext); | ||||||
|         expect(searchResults.length).toEqual(4); |         expect(searchResults.length).toEqual(4); | ||||||
|         expect(noteCache.notes[searchResults[0].noteId].title).toEqual("Austria"); |         expect(becca.notes[searchResults[0].noteId].title).toEqual("Austria"); | ||||||
|         expect(noteCache.notes[searchResults[1].noteId].title).toEqual("Italy"); |         expect(becca.notes[searchResults[1].noteId].title).toEqual("Italy"); | ||||||
|         expect(noteCache.notes[searchResults[2].noteId].title).toEqual("Slovakia"); |         expect(becca.notes[searchResults[2].noteId].title).toEqual("Slovakia"); | ||||||
|         expect(noteCache.notes[searchResults[3].noteId].title).toEqual("Ukraine"); |         expect(becca.notes[searchResults[3].noteId].title).toEqual("Ukraine"); | ||||||
|  |  | ||||||
|         searchResults = searchService.findNotesWithQuery('# note.parents.title = Europe orderBy note.labels.capital', searchContext); |         searchResults = searchService.findNotesWithQuery('# note.parents.title = Europe orderBy note.labels.capital', searchContext); | ||||||
|         expect(searchResults.length).toEqual(4); |         expect(searchResults.length).toEqual(4); | ||||||
|         expect(noteCache.notes[searchResults[0].noteId].title).toEqual("Slovakia"); |         expect(becca.notes[searchResults[0].noteId].title).toEqual("Slovakia"); | ||||||
|         expect(noteCache.notes[searchResults[1].noteId].title).toEqual("Ukraine"); |         expect(becca.notes[searchResults[1].noteId].title).toEqual("Ukraine"); | ||||||
|         expect(noteCache.notes[searchResults[2].noteId].title).toEqual("Italy"); |         expect(becca.notes[searchResults[2].noteId].title).toEqual("Italy"); | ||||||
|         expect(noteCache.notes[searchResults[3].noteId].title).toEqual("Austria"); |         expect(becca.notes[searchResults[3].noteId].title).toEqual("Austria"); | ||||||
|  |  | ||||||
|         searchResults = searchService.findNotesWithQuery('# note.parents.title = Europe orderBy note.labels.capital DESC', searchContext); |         searchResults = searchService.findNotesWithQuery('# note.parents.title = Europe orderBy note.labels.capital DESC', searchContext); | ||||||
|         expect(searchResults.length).toEqual(4); |         expect(searchResults.length).toEqual(4); | ||||||
|         expect(noteCache.notes[searchResults[0].noteId].title).toEqual("Austria"); |         expect(becca.notes[searchResults[0].noteId].title).toEqual("Austria"); | ||||||
|         expect(noteCache.notes[searchResults[1].noteId].title).toEqual("Italy"); |         expect(becca.notes[searchResults[1].noteId].title).toEqual("Italy"); | ||||||
|         expect(noteCache.notes[searchResults[2].noteId].title).toEqual("Ukraine"); |         expect(becca.notes[searchResults[2].noteId].title).toEqual("Ukraine"); | ||||||
|         expect(noteCache.notes[searchResults[3].noteId].title).toEqual("Slovakia"); |         expect(becca.notes[searchResults[3].noteId].title).toEqual("Slovakia"); | ||||||
|  |  | ||||||
|         searchResults = searchService.findNotesWithQuery('# note.parents.title = Europe orderBy note.labels.capital DESC limit 2', searchContext); |         searchResults = searchService.findNotesWithQuery('# note.parents.title = Europe orderBy note.labels.capital DESC limit 2', searchContext); | ||||||
|         expect(searchResults.length).toEqual(2); |         expect(searchResults.length).toEqual(2); | ||||||
|         expect(noteCache.notes[searchResults[0].noteId].title).toEqual("Austria"); |         expect(becca.notes[searchResults[0].noteId].title).toEqual("Austria"); | ||||||
|         expect(noteCache.notes[searchResults[1].noteId].title).toEqual("Italy"); |         expect(becca.notes[searchResults[1].noteId].title).toEqual("Italy"); | ||||||
|  |  | ||||||
|         searchResults = searchService.findNotesWithQuery('# note.parents.title = Europe orderBy #capital DESC limit 1', searchContext); |         searchResults = searchService.findNotesWithQuery('# note.parents.title = Europe orderBy #capital DESC limit 1', searchContext); | ||||||
|         expect(searchResults.length).toEqual(1); |         expect(searchResults.length).toEqual(1); | ||||||
| @@ -582,11 +582,11 @@ describe("Search", () => { | |||||||
|  |  | ||||||
|         let searchResults = searchService.findNotesWithQuery('# not(#capital) and note.noteId != root', searchContext); |         let searchResults = searchService.findNotesWithQuery('# not(#capital) and note.noteId != root', searchContext); | ||||||
|         expect(searchResults.length).toEqual(1); |         expect(searchResults.length).toEqual(1); | ||||||
|         expect(noteCache.notes[searchResults[0].noteId].title).toEqual("Europe"); |         expect(becca.notes[searchResults[0].noteId].title).toEqual("Europe"); | ||||||
|  |  | ||||||
|         searchResults = searchService.findNotesWithQuery('#!capital and note.noteId != root', searchContext); |         searchResults = searchService.findNotesWithQuery('#!capital and note.noteId != root', searchContext); | ||||||
|         expect(searchResults.length).toEqual(1); |         expect(searchResults.length).toEqual(1); | ||||||
|         expect(noteCache.notes[searchResults[0].noteId].title).toEqual("Europe"); |         expect(becca.notes[searchResults[0].noteId].title).toEqual("Europe"); | ||||||
|     }); |     }); | ||||||
|  |  | ||||||
|     it("test note.text *=* something", () => { |     it("test note.text *=* something", () => { | ||||||
| @@ -602,7 +602,7 @@ describe("Search", () => { | |||||||
|  |  | ||||||
|         let searchResults = searchService.findNotesWithQuery('# note.text *=* vaki and note.noteId != root', searchContext); |         let searchResults = searchService.findNotesWithQuery('# note.text *=* vaki and note.noteId != root', searchContext); | ||||||
|         expect(searchResults.length).toEqual(1); |         expect(searchResults.length).toEqual(1); | ||||||
|         expect(noteCache.notes[searchResults[0].noteId].title).toEqual("Slovakia"); |         expect(becca.notes[searchResults[0].noteId].title).toEqual("Slovakia"); | ||||||
|     }); |     }); | ||||||
|  |  | ||||||
|     it("test that fulltext does not match archived notes", () => { |     it("test that fulltext does not match archived notes", () => { | ||||||
| @@ -619,7 +619,7 @@ describe("Search", () => { | |||||||
|  |  | ||||||
|         let searchResults = searchService.findNotesWithQuery('reddit', searchContext); |         let searchResults = searchService.findNotesWithQuery('reddit', searchContext); | ||||||
|         expect(searchResults.length).toEqual(1); |         expect(searchResults.length).toEqual(1); | ||||||
|         expect(noteCache.notes[searchResults[0].noteId].title).toEqual("Reddit is bad"); |         expect(becca.notes[searchResults[0].noteId].title).toEqual("Reddit is bad"); | ||||||
|     }); |     }); | ||||||
|  |  | ||||||
|     // FIXME: test what happens when we order without any filter criteria |     // FIXME: test what happens when we order without any filter criteria | ||||||
|   | |||||||
| @@ -1,13 +1,13 @@ | |||||||
| const {note} = require('./note_cache_mocking.js'); | const {note} = require('./note_cache_mocking.js'); | ||||||
| const ValueExtractor = require('../../src/services/search/value_extractor.js'); | const ValueExtractor = require('../../src/services/search/value_extractor.js'); | ||||||
| const noteCache = require('../../src/services/note_cache/note_cache.js'); | const becca = require('../../src/services/note_cache/note_cache.js'); | ||||||
| const SearchContext = require("../../src/services/search/search_context.js"); | const SearchContext = require("../../src/services/search/search_context.js"); | ||||||
|  |  | ||||||
| const dsc = new SearchContext(); | const dsc = new SearchContext(); | ||||||
|  |  | ||||||
| describe("Value extractor", () => { | describe("Value extractor", () => { | ||||||
|     beforeEach(() => { |     beforeEach(() => { | ||||||
|         noteCache.reset(); |         becca.reset(); | ||||||
|     }); |     }); | ||||||
|  |  | ||||||
|     it("simple title extraction", async () => { |     it("simple title extraction", async () => { | ||||||
|   | |||||||
| @@ -399,7 +399,7 @@ class Note extends Entity { | |||||||
|                 return false; |                 return false; | ||||||
|             } |             } | ||||||
|  |  | ||||||
|             // FIXME: this code is quite questionable, one problem is that other caches (Froca, NoteCache) have nothing like that |             // FIXME: this code is quite questionable, one problem is that other caches (Froca, Becca) have nothing like that | ||||||
|             if (attr.isDefinition()) { |             if (attr.isDefinition()) { | ||||||
|                 const firstDefinitionIndex = attributes.findIndex(el => el.type === attr.type && el.name === attr.name); |                 const firstDefinitionIndex = attributes.findIndex(el => el.type === attr.type && el.name === attr.name); | ||||||
|  |  | ||||||
|   | |||||||
| @@ -1,6 +1,6 @@ | |||||||
| "use strict"; | "use strict"; | ||||||
|  |  | ||||||
| const noteCacheService = require('../../services/note_cache/note_cache_service'); | const beccaService = require('../../services/note_cache/note_cache_service'); | ||||||
| const searchService = require('../../services/search/services/search.js'); | const searchService = require('../../services/search/services/search.js'); | ||||||
| const repository = require('../../services/repository'); | const repository = require('../../services/repository'); | ||||||
| const log = require('../../services/log'); | const log = require('../../services/log'); | ||||||
| @@ -58,8 +58,8 @@ function getRecentNotes(activeNoteId) { | |||||||
|     return recentNotes.map(rn => { |     return recentNotes.map(rn => { | ||||||
|         const notePathArray = rn.notePath.split('/'); |         const notePathArray = rn.notePath.split('/'); | ||||||
|  |  | ||||||
|         const noteTitle = noteCacheService.getNoteTitle(notePathArray[notePathArray.length - 1]); |         const noteTitle = beccaService.getNoteTitle(notePathArray[notePathArray.length - 1]); | ||||||
|         const notePathTitle = noteCacheService.getNoteTitleForPath(notePathArray); |         const notePathTitle = beccaService.getNoteTitleForPath(notePathArray); | ||||||
|  |  | ||||||
|         return { |         return { | ||||||
|             notePath: rn.notePath, |             notePath: rn.notePath, | ||||||
|   | |||||||
| @@ -5,7 +5,7 @@ const utils = require('../../services/utils'); | |||||||
| const entityChangesService = require('../../services/entity_changes.js'); | const entityChangesService = require('../../services/entity_changes.js'); | ||||||
| const treeService = require('../../services/tree'); | const treeService = require('../../services/tree'); | ||||||
| const noteService = require('../../services/notes'); | const noteService = require('../../services/notes'); | ||||||
| const noteCache = require('../../services/note_cache/note_cache'); | const becca = require('../../services/note_cache/note_cache'); | ||||||
| const repository = require('../../services/repository'); | const repository = require('../../services/repository'); | ||||||
| const TaskContext = require('../../services/task_context'); | const TaskContext = require('../../services/task_context'); | ||||||
|  |  | ||||||
| @@ -137,7 +137,7 @@ function setExpanded(req) { | |||||||
|         // we don't sync expanded label |         // we don't sync expanded label | ||||||
|         // also this does not trigger updates to the frontend, this would trigger too many reloads |         // also this does not trigger updates to the frontend, this would trigger too many reloads | ||||||
|  |  | ||||||
|         const branch = noteCache.branches[branchId]; |         const branch = becca.branches[branchId]; | ||||||
|  |  | ||||||
|         if (branch) { |         if (branch) { | ||||||
|             branch.isExpanded = !!expanded; |             branch.isExpanded = !!expanded; | ||||||
| @@ -166,7 +166,7 @@ function setExpandedForSubtree(req) { | |||||||
|     sql.executeMany(`UPDATE branches SET isExpanded = ${expanded} WHERE branchId IN (???)`, branchIds); |     sql.executeMany(`UPDATE branches SET isExpanded = ${expanded} WHERE branchId IN (???)`, branchIds); | ||||||
|  |  | ||||||
|     for (const branchId of branchIds) { |     for (const branchId of branchIds) { | ||||||
|         const branch = noteCache.branches[branchId]; |         const branch = becca.branches[branchId]; | ||||||
|  |  | ||||||
|         if (branch) { |         if (branch) { | ||||||
|             branch.isExpanded = !!expanded; |             branch.isExpanded = !!expanded; | ||||||
|   | |||||||
| @@ -7,7 +7,7 @@ const zipImportService = require('../../services/import/zip'); | |||||||
| const singleImportService = require('../../services/import/single'); | const singleImportService = require('../../services/import/single'); | ||||||
| const cls = require('../../services/cls'); | const cls = require('../../services/cls'); | ||||||
| const path = require('path'); | const path = require('path'); | ||||||
| const noteCacheLoader = require('../../services/note_cache/note_cache_loader.js'); | const beccaLoader = require('../../services/note_cache/note_cache_loader.js'); | ||||||
| const log = require('../../services/log'); | const log = require('../../services/log'); | ||||||
| const TaskContext = require('../../services/task_context.js'); | const TaskContext = require('../../services/task_context.js'); | ||||||
|  |  | ||||||
| @@ -77,10 +77,10 @@ async function importToBranch(req) { | |||||||
|         }), 1000); |         }), 1000); | ||||||
|     } |     } | ||||||
|  |  | ||||||
|     // import has deactivated note events so note cache is not updated |     // import has deactivated note events so becca is not updated | ||||||
|     // instead we force it to reload (can be async) |     // instead we force it to reload (can be async) | ||||||
|  |  | ||||||
|     noteCacheLoader.load(); |     beccaLoader.load(); | ||||||
|  |  | ||||||
|     return note; |     return note; | ||||||
| } | } | ||||||
|   | |||||||
| @@ -1,7 +1,7 @@ | |||||||
| "use strict"; | "use strict"; | ||||||
|  |  | ||||||
| const repository = require('../../services/repository'); | const repository = require('../../services/repository'); | ||||||
| const noteCacheService = require('../../services/note_cache/note_cache_service'); | const beccaService = require('../../services/note_cache/note_cache_service'); | ||||||
| const protectedSessionService = require('../../services/protected_session'); | const protectedSessionService = require('../../services/protected_session'); | ||||||
| const noteRevisionService = require('../../services/note_revisions'); | const noteRevisionService = require('../../services/note_revisions'); | ||||||
| const utils = require('../../services/utils'); | const utils = require('../../services/utils'); | ||||||
| @@ -121,7 +121,7 @@ function getEditedNotesOnDate(req) { | |||||||
|         LIMIT 50`, {date: req.params.date + '%'}); |         LIMIT 50`, {date: req.params.date + '%'}); | ||||||
|  |  | ||||||
|     for (const note of notes) { |     for (const note of notes) { | ||||||
|         const notePath = note.isDeleted ? null : noteCacheService.getNotePath(note.noteId); |         const notePath = note.isDeleted ? null : beccaService.getNotePath(note.noteId); | ||||||
|  |  | ||||||
|         note.notePath = notePath ? notePath.notePath : null; |         note.notePath = notePath ? notePath.notePath : null; | ||||||
|     } |     } | ||||||
|   | |||||||
| @@ -3,7 +3,7 @@ | |||||||
| const sql = require('../../services/sql'); | const sql = require('../../services/sql'); | ||||||
| const protectedSessionService = require('../../services/protected_session'); | const protectedSessionService = require('../../services/protected_session'); | ||||||
| const noteService = require('../../services/notes'); | const noteService = require('../../services/notes'); | ||||||
| const noteCacheService = require('../../services/note_cache/note_cache_service'); | const beccaService = require('../../services/note_cache/note_cache_service'); | ||||||
|  |  | ||||||
| function getRecentChanges(req) { | function getRecentChanges(req) { | ||||||
|     const {ancestorNoteId} = req.params; |     const {ancestorNoteId} = req.params; | ||||||
| @@ -25,7 +25,7 @@ function getRecentChanges(req) { | |||||||
|             JOIN notes USING(noteId)`); |             JOIN notes USING(noteId)`); | ||||||
|  |  | ||||||
|     for (const noteRevision of noteRevisions) { |     for (const noteRevision of noteRevisions) { | ||||||
|         if (noteCacheService.isInAncestor(noteRevision.noteId, ancestorNoteId)) { |         if (beccaService.isInAncestor(noteRevision.noteId, ancestorNoteId)) { | ||||||
|             recentChanges.push(noteRevision); |             recentChanges.push(noteRevision); | ||||||
|         } |         } | ||||||
|     } |     } | ||||||
| @@ -58,7 +58,7 @@ function getRecentChanges(req) { | |||||||
|             WHERE notes.isDeleted = 1`); |             WHERE notes.isDeleted = 1`); | ||||||
|  |  | ||||||
|     for (const note of notes) { |     for (const note of notes) { | ||||||
|         if (noteCacheService.isInAncestor(note.noteId, ancestorNoteId)) { |         if (beccaService.isInAncestor(note.noteId, ancestorNoteId)) { | ||||||
|             recentChanges.push(note); |             recentChanges.push(note); | ||||||
|         } |         } | ||||||
|     } |     } | ||||||
|   | |||||||
| @@ -1,5 +1,5 @@ | |||||||
| const sql = require('../../services/sql'); | const sql = require('../../services/sql'); | ||||||
| const noteCache = require('../../services/note_cache/note_cache'); | const becca = require('../../services/note_cache/note_cache'); | ||||||
|  |  | ||||||
| function getNoteSize(req) { | function getNoteSize(req) { | ||||||
|     const {noteId} = req.params; |     const {noteId} = req.params; | ||||||
| @@ -23,7 +23,7 @@ function getNoteSize(req) { | |||||||
|  |  | ||||||
| function getSubtreeSize(req) { | function getSubtreeSize(req) { | ||||||
|     const {noteId} = req.params; |     const {noteId} = req.params; | ||||||
|     const note = noteCache.notes[noteId]; |     const note = becca.notes[noteId]; | ||||||
|  |  | ||||||
|     if (!note) { |     if (!note) { | ||||||
|         return [404, `Note ${noteId} was not found.`]; |         return [404, `Note ${noteId} was not found.`]; | ||||||
|   | |||||||
| @@ -1,6 +1,6 @@ | |||||||
| "use strict"; | "use strict"; | ||||||
|  |  | ||||||
| const noteCache = require('../../services/note_cache/note_cache'); | const becca = require('../../services/note_cache/note_cache'); | ||||||
| const log = require('../../services/log'); | const log = require('../../services/log'); | ||||||
|  |  | ||||||
| function getNotesAndBranchesAndAttributes(noteIds) { | function getNotesAndBranchesAndAttributes(noteIds) { | ||||||
| @@ -23,7 +23,7 @@ function getNotesAndBranchesAndAttributes(noteIds) { | |||||||
|         } |         } | ||||||
|  |  | ||||||
|         for (const childNote of note.children) { |         for (const childNote of note.children) { | ||||||
|             const childBranch = noteCache.getBranch(childNote.noteId, note.noteId); |             const childBranch = becca.getBranch(childNote.noteId, note.noteId); | ||||||
|  |  | ||||||
|             collectedBranchIds.add(childBranch.branchId); |             collectedBranchIds.add(childBranch.branchId); | ||||||
|         } |         } | ||||||
| @@ -38,7 +38,7 @@ function getNotesAndBranchesAndAttributes(noteIds) { | |||||||
|     } |     } | ||||||
|  |  | ||||||
|     for (const noteId of noteIds) { |     for (const noteId of noteIds) { | ||||||
|         const note = noteCache.notes[noteId]; |         const note = becca.notes[noteId]; | ||||||
|  |  | ||||||
|         if (!note) { |         if (!note) { | ||||||
|             continue; |             continue; | ||||||
| @@ -50,7 +50,7 @@ function getNotesAndBranchesAndAttributes(noteIds) { | |||||||
|     const notes = []; |     const notes = []; | ||||||
|  |  | ||||||
|     for (const noteId of collectedNoteIds) { |     for (const noteId of collectedNoteIds) { | ||||||
|         const note = noteCache.notes[noteId]; |         const note = becca.notes[noteId]; | ||||||
|  |  | ||||||
|         notes.push({ |         notes.push({ | ||||||
|             noteId: note.noteId, |             noteId: note.noteId, | ||||||
| @@ -75,7 +75,7 @@ function getNotesAndBranchesAndAttributes(noteIds) { | |||||||
|     } |     } | ||||||
|  |  | ||||||
|     for (const branchId of collectedBranchIds) { |     for (const branchId of collectedBranchIds) { | ||||||
|         const branch = noteCache.branches[branchId]; |         const branch = becca.branches[branchId]; | ||||||
|  |  | ||||||
|         if (!branch) { |         if (!branch) { | ||||||
|             log.error(`Could not find branch for branchId=${branchId}`); |             log.error(`Could not find branch for branchId=${branchId}`); | ||||||
| @@ -95,7 +95,7 @@ function getNotesAndBranchesAndAttributes(noteIds) { | |||||||
|     const attributes = []; |     const attributes = []; | ||||||
|  |  | ||||||
|     for (const attributeId of collectedAttributeIds) { |     for (const attributeId of collectedAttributeIds) { | ||||||
|         const attribute = noteCache.attributes[attributeId]; |         const attribute = becca.attributes[attributeId]; | ||||||
|  |  | ||||||
|         attributes.push({ |         attributes.push({ | ||||||
|             attributeId: attribute.attributeId, |             attributeId: attribute.attributeId, | ||||||
| @@ -127,7 +127,7 @@ function getTree(req) { | |||||||
|         for (const childNote of parentNote.children) { |         for (const childNote of parentNote.children) { | ||||||
|             collectedNoteIds.add(childNote.noteId); |             collectedNoteIds.add(childNote.noteId); | ||||||
|  |  | ||||||
|             const childBranch = noteCache.getBranch(childNote.noteId, parentNote.noteId); |             const childBranch = becca.getBranch(childNote.noteId, parentNote.noteId); | ||||||
|  |  | ||||||
|             if (childBranch.isExpanded) { |             if (childBranch.isExpanded) { | ||||||
|                 collect(childBranch.childNote); |                 collect(childBranch.childNote); | ||||||
| @@ -135,11 +135,11 @@ function getTree(req) { | |||||||
|         } |         } | ||||||
|     } |     } | ||||||
|  |  | ||||||
|     if (!(subTreeNoteId in noteCache.notes)) { |     if (!(subTreeNoteId in becca.notes)) { | ||||||
|         return [404, `Note ${subTreeNoteId} not found in the cache`]; |         return [404, `Note ${subTreeNoteId} not found in the cache`]; | ||||||
|     } |     } | ||||||
|  |  | ||||||
|     collect(noteCache.notes[subTreeNoteId]); |     collect(becca.notes[subTreeNoteId]); | ||||||
|  |  | ||||||
|     return getNotesAndBranchesAndAttributes(collectedNoteIds); |     return getNotesAndBranchesAndAttributes(collectedNoteIds); | ||||||
| } | } | ||||||
|   | |||||||
| @@ -2,7 +2,7 @@ | |||||||
|  |  | ||||||
| const repository = require('./repository'); | const repository = require('./repository'); | ||||||
| const sql = require('./sql'); | const sql = require('./sql'); | ||||||
| const noteCache = require('./note_cache/note_cache'); | const becca = require('./note_cache/note_cache'); | ||||||
| const Attribute = require('../entities/attribute'); | const Attribute = require('../entities/attribute'); | ||||||
|  |  | ||||||
| const ATTRIBUTE_TYPES = [ 'label', 'relation' ]; | const ATTRIBUTE_TYPES = [ 'label', 'relation' ]; | ||||||
| @@ -75,7 +75,7 @@ function getNoteIdsWithLabels(names) { | |||||||
|     const noteIds = new Set(); |     const noteIds = new Set(); | ||||||
|  |  | ||||||
|     for (const name of names) { |     for (const name of names) { | ||||||
|         for (const attr of noteCache.findAttributes('label', name)) { |         for (const attr of becca.findAttributes('label', name)) { | ||||||
|             noteIds.add(attr.noteId); |             noteIds.add(attr.noteId); | ||||||
|         } |         } | ||||||
|     } |     } | ||||||
|   | |||||||
| @@ -3,7 +3,7 @@ const scriptService = require('./script'); | |||||||
| const treeService = require('./tree'); | const treeService = require('./tree'); | ||||||
| const noteService = require('./notes'); | const noteService = require('./notes'); | ||||||
| const repository = require('./repository'); | const repository = require('./repository'); | ||||||
| const noteCache = require('./note_cache/note_cache'); | const becca = require('./note_cache/note_cache'); | ||||||
| const Attribute = require('../entities/attribute'); | const Attribute = require('../entities/attribute'); | ||||||
|  |  | ||||||
| function runAttachedRelations(note, relationName, originEntity) { | function runAttachedRelations(note, relationName, originEntity) { | ||||||
| @@ -23,7 +23,7 @@ eventService.subscribe(eventService.NOTE_TITLE_CHANGED, note => { | |||||||
|     runAttachedRelations(note, 'runOnNoteTitleChange', note); |     runAttachedRelations(note, 'runOnNoteTitleChange', note); | ||||||
|  |  | ||||||
|     if (!note.isRoot()) { |     if (!note.isRoot()) { | ||||||
|         const noteFromCache = noteCache.notes[note.noteId]; |         const noteFromCache = becca.notes[note.noteId]; | ||||||
|  |  | ||||||
|         if (!noteFromCache) { |         if (!noteFromCache) { | ||||||
|             return; |             return; | ||||||
| @@ -87,7 +87,7 @@ eventService.subscribe(eventService.ENTITY_CREATED, ({ entityName, entity }) => | |||||||
|             treeService.sortNotesByTitle(entity.noteId); |             treeService.sortNotesByTitle(entity.noteId); | ||||||
|  |  | ||||||
|             if (entity.isInheritable) { |             if (entity.isInheritable) { | ||||||
|                 const note = noteCache.notes[entity.noteId]; |                 const note = becca.notes[entity.noteId]; | ||||||
|  |  | ||||||
|                 if (note) { |                 if (note) { | ||||||
|                     for (const noteId of note.subtreeNoteIds) { |                     for (const noteId of note.subtreeNoteIds) { | ||||||
|   | |||||||
| @@ -3,9 +3,9 @@ | |||||||
| const Note = require('./note.js'); | const Note = require('./note.js'); | ||||||
|  |  | ||||||
| class Attribute { | class Attribute { | ||||||
|     constructor(noteCache, row) { |     constructor(becca, row) { | ||||||
|         /** @param {NoteCache} */ |         /** @param {Becca} */ | ||||||
|         this.noteCache = noteCache; |         this.becca = becca; | ||||||
|         /** @param {string} */ |         /** @param {string} */ | ||||||
|         this.attributeId = row.attributeId; |         this.attributeId = row.attributeId; | ||||||
|         /** @param {string} */ |         /** @param {string} */ | ||||||
| @@ -21,18 +21,18 @@ class Attribute { | |||||||
|         /** @param {boolean} */ |         /** @param {boolean} */ | ||||||
|         this.isInheritable = !!row.isInheritable; |         this.isInheritable = !!row.isInheritable; | ||||||
|  |  | ||||||
|         this.noteCache.attributes[this.attributeId] = this; |         this.becca.attributes[this.attributeId] = this; | ||||||
|  |  | ||||||
|         if (!(this.noteId in this.noteCache.notes)) { |         if (!(this.noteId in this.becca.notes)) { | ||||||
|             // entities can come out of order in sync, create skeleton which will be filled later |             // entities can come out of order in sync, create skeleton which will be filled later | ||||||
|             this.noteCache.notes[this.noteId] = new Note(this.noteCache, {noteId: this.noteId}); |             this.becca.notes[this.noteId] = new Note(this.becca, {noteId: this.noteId}); | ||||||
|         } |         } | ||||||
|  |  | ||||||
|         this.noteCache.notes[this.noteId].ownedAttributes.push(this); |         this.becca.notes[this.noteId].ownedAttributes.push(this); | ||||||
|  |  | ||||||
|         const key = `${this.type}-${this.name.toLowerCase()}`; |         const key = `${this.type}-${this.name.toLowerCase()}`; | ||||||
|         this.noteCache.attributeIndex[key] = this.noteCache.attributeIndex[key] || []; |         this.becca.attributeIndex[key] = this.becca.attributeIndex[key] || []; | ||||||
|         this.noteCache.attributeIndex[key].push(this); |         this.becca.attributeIndex[key].push(this); | ||||||
|  |  | ||||||
|         const targetNote = this.targetNote; |         const targetNote = this.targetNote; | ||||||
|  |  | ||||||
| @@ -51,12 +51,12 @@ class Attribute { | |||||||
|     } |     } | ||||||
|  |  | ||||||
|     get note() { |     get note() { | ||||||
|         return this.noteCache.notes[this.noteId]; |         return this.becca.notes[this.noteId]; | ||||||
|     } |     } | ||||||
|  |  | ||||||
|     get targetNote() { |     get targetNote() { | ||||||
|         if (this.type === 'relation') { |         if (this.type === 'relation') { | ||||||
|             return this.noteCache.notes[this.value]; |             return this.becca.notes[this.value]; | ||||||
|         } |         } | ||||||
|     } |     } | ||||||
|  |  | ||||||
| @@ -64,7 +64,7 @@ class Attribute { | |||||||
|     get pojo() { |     get pojo() { | ||||||
|         const pojo = {...this}; |         const pojo = {...this}; | ||||||
|  |  | ||||||
|         delete pojo.noteCache; |         delete pojo.becca; | ||||||
|  |  | ||||||
|         return pojo; |         return pojo; | ||||||
|     } |     } | ||||||
|   | |||||||
| @@ -3,9 +3,9 @@ | |||||||
| const Note = require('./note.js'); | const Note = require('./note.js'); | ||||||
|  |  | ||||||
| class Branch { | class Branch { | ||||||
|     constructor(noteCache, row) { |     constructor(becca, row) { | ||||||
|         /** @param {NoteCache} */ |         /** @param {Becca} */ | ||||||
|         this.noteCache = noteCache; |         this.becca = becca; | ||||||
|         /** @param {string} */ |         /** @param {string} */ | ||||||
|         this.branchId = row.branchId; |         this.branchId = row.branchId; | ||||||
|         /** @param {string} */ |         /** @param {string} */ | ||||||
| @@ -31,35 +31,35 @@ class Branch { | |||||||
|  |  | ||||||
|         parentNote.children.push(childNote); |         parentNote.children.push(childNote); | ||||||
|  |  | ||||||
|         this.noteCache.branches[this.branchId] = this; |         this.becca.branches[this.branchId] = this; | ||||||
|         this.noteCache.childParentToBranch[`${this.noteId}-${this.parentNoteId}`] = this; |         this.becca.childParentToBranch[`${this.noteId}-${this.parentNoteId}`] = this; | ||||||
|     } |     } | ||||||
|  |  | ||||||
|     /** @return {Note} */ |     /** @return {Note} */ | ||||||
|     get childNote() { |     get childNote() { | ||||||
|         if (!(this.noteId in this.noteCache.notes)) { |         if (!(this.noteId in this.becca.notes)) { | ||||||
|             // entities can come out of order in sync, create skeleton which will be filled later |             // entities can come out of order in sync, create skeleton which will be filled later | ||||||
|             this.noteCache.notes[this.noteId] = new Note(this.noteCache, {noteId: this.noteId}); |             this.becca.notes[this.noteId] = new Note(this.becca, {noteId: this.noteId}); | ||||||
|         } |         } | ||||||
|  |  | ||||||
|         return this.noteCache.notes[this.noteId]; |         return this.becca.notes[this.noteId]; | ||||||
|     } |     } | ||||||
|  |  | ||||||
|     /** @return {Note} */ |     /** @return {Note} */ | ||||||
|     get parentNote() { |     get parentNote() { | ||||||
|         if (!(this.parentNoteId in this.noteCache.notes)) { |         if (!(this.parentNoteId in this.becca.notes)) { | ||||||
|             // entities can come out of order in sync, create skeleton which will be filled later |             // entities can come out of order in sync, create skeleton which will be filled later | ||||||
|             this.noteCache.notes[this.parentNoteId] = new Note(this.noteCache, {noteId: this.parentNoteId}); |             this.becca.notes[this.parentNoteId] = new Note(this.becca, {noteId: this.parentNoteId}); | ||||||
|         } |         } | ||||||
|  |  | ||||||
|         return this.noteCache.notes[this.parentNoteId]; |         return this.becca.notes[this.parentNoteId]; | ||||||
|     } |     } | ||||||
|  |  | ||||||
|     // for logging etc |     // for logging etc | ||||||
|     get pojo() { |     get pojo() { | ||||||
|         const pojo = {...this}; |         const pojo = {...this}; | ||||||
|  |  | ||||||
|         delete pojo.noteCache; |         delete pojo.becca; | ||||||
|  |  | ||||||
|         return pojo; |         return pojo; | ||||||
|     } |     } | ||||||
|   | |||||||
| @@ -4,9 +4,9 @@ const protectedSessionService = require('../../protected_session'); | |||||||
| const log = require('../../log'); | const log = require('../../log'); | ||||||
|  |  | ||||||
| class Note { | class Note { | ||||||
|     constructor(noteCache, row) { |     constructor(becca, row) { | ||||||
|         /** @param {NoteCache} */ |         /** @param {Becca} */ | ||||||
|         this.noteCache = noteCache; |         this.becca = becca; | ||||||
|  |  | ||||||
|         this.update(row); |         this.update(row); | ||||||
|  |  | ||||||
| @@ -27,7 +27,7 @@ class Note { | |||||||
|         /** @param {Attribute[]} */ |         /** @param {Attribute[]} */ | ||||||
|         this.targetRelations = []; |         this.targetRelations = []; | ||||||
|  |  | ||||||
|         this.noteCache.notes[this.noteId] = this; |         this.becca.notes[this.noteId] = this; | ||||||
|  |  | ||||||
|         /** @param {Note[]|null} */ |         /** @param {Note[]|null} */ | ||||||
|         this.ancestorCache = null; |         this.ancestorCache = null; | ||||||
| @@ -94,7 +94,7 @@ class Note { | |||||||
|  |  | ||||||
|             for (const ownedAttr of parentAttributes) { // parentAttributes so we process also inherited templates |             for (const ownedAttr of parentAttributes) { // parentAttributes so we process also inherited templates | ||||||
|                 if (ownedAttr.type === 'relation' && ownedAttr.name === 'template') { |                 if (ownedAttr.type === 'relation' && ownedAttr.name === 'template') { | ||||||
|                     const templateNote = this.noteCache.notes[ownedAttr.value]; |                     const templateNote = this.becca.notes[ownedAttr.value]; | ||||||
|  |  | ||||||
|                     if (templateNote) { |                     if (templateNote) { | ||||||
|                         templateAttributes.push(...templateNote.__getAttributes(newPath)); |                         templateAttributes.push(...templateNote.__getAttributes(newPath)); | ||||||
| @@ -440,7 +440,7 @@ class Note { | |||||||
|     get pojo() { |     get pojo() { | ||||||
|         const pojo = {...this}; |         const pojo = {...this}; | ||||||
|  |  | ||||||
|         delete pojo.noteCache; |         delete pojo.becca; | ||||||
|         delete pojo.ancestorCache; |         delete pojo.ancestorCache; | ||||||
|         delete pojo.attributeCache; |         delete pojo.attributeCache; | ||||||
|         delete pojo.flatTextCache; |         delete pojo.flatTextCache; | ||||||
|   | |||||||
| @@ -1,6 +1,6 @@ | |||||||
| "use strict"; | "use strict"; | ||||||
|  |  | ||||||
| class NoteCache { | class Becca { | ||||||
|     constructor() { |     constructor() { | ||||||
|         this.reset(); |         this.reset(); | ||||||
|     } |     } | ||||||
| @@ -50,6 +50,6 @@ class NoteCache { | |||||||
|     } |     } | ||||||
| } | } | ||||||
|  |  | ||||||
| const noteCache = new NoteCache(); | const becca = new Becca(); | ||||||
|  |  | ||||||
| module.exports = noteCache; | module.exports = becca; | ||||||
|   | |||||||
| @@ -2,7 +2,7 @@ | |||||||
|  |  | ||||||
| const sql = require('../sql.js'); | const sql = require('../sql.js'); | ||||||
| const eventService = require('../events.js'); | const eventService = require('../events.js'); | ||||||
| const noteCache = require('./note_cache'); | const becca = require('./note_cache'); | ||||||
| const sqlInit = require('../sql_init'); | const sqlInit = require('../sql_init'); | ||||||
| const log = require('../log'); | const log = require('../log'); | ||||||
| const Note = require('./entities/note'); | const Note = require('./entities/note'); | ||||||
| @@ -15,29 +15,29 @@ sqlInit.dbReady.then(() => { | |||||||
|  |  | ||||||
| function load() { | function load() { | ||||||
|     const start = Date.now(); |     const start = Date.now(); | ||||||
|     noteCache.reset(); |     becca.reset(); | ||||||
|  |  | ||||||
|     for (const row of sql.iterateRows(`SELECT noteId, title, type, mime, isProtected, dateCreated, dateModified, utcDateCreated, utcDateModified FROM notes WHERE isDeleted = 0`, [])) { |     for (const row of sql.iterateRows(`SELECT noteId, title, type, mime, isProtected, dateCreated, dateModified, utcDateCreated, utcDateModified FROM notes WHERE isDeleted = 0`, [])) { | ||||||
|         new Note(noteCache, row); |         new Note(becca, row); | ||||||
|     } |     } | ||||||
|  |  | ||||||
|     for (const row of sql.iterateRows(`SELECT branchId, noteId, parentNoteId, prefix, notePosition, isExpanded FROM branches WHERE isDeleted = 0`, [])) { |     for (const row of sql.iterateRows(`SELECT branchId, noteId, parentNoteId, prefix, notePosition, isExpanded FROM branches WHERE isDeleted = 0`, [])) { | ||||||
|         const branch = new Branch(noteCache, row); |         const branch = new Branch(becca, row); | ||||||
|     } |     } | ||||||
|  |  | ||||||
|     for (const row of sql.iterateRows(`SELECT attributeId, noteId, type, name, value, isInheritable, position FROM attributes WHERE isDeleted = 0`, [])) { |     for (const row of sql.iterateRows(`SELECT attributeId, noteId, type, name, value, isInheritable, position FROM attributes WHERE isDeleted = 0`, [])) { | ||||||
|         new Attribute(noteCache, row); |         new Attribute(becca, row); | ||||||
|     } |     } | ||||||
|  |  | ||||||
|     noteCache.loaded = true; |     becca.loaded = true; | ||||||
|  |  | ||||||
|     log.info(`Note cache load took ${Date.now() - start}ms`); |     log.info(`Becca (note cache) load took ${Date.now() - start}ms`); | ||||||
| } | } | ||||||
|  |  | ||||||
| eventService.subscribe([eventService.ENTITY_CHANGED, eventService.ENTITY_DELETED, eventService.ENTITY_SYNCED],  ({entityName, entity}) => { | eventService.subscribe([eventService.ENTITY_CHANGED, eventService.ENTITY_DELETED, eventService.ENTITY_SYNCED],  ({entityName, entity}) => { | ||||||
|     // note that entity can also be just POJO without methods if coming from sync |     // note that entity can also be just POJO without methods if coming from sync | ||||||
|  |  | ||||||
|     if (!noteCache.loaded) { |     if (!becca.loaded) { | ||||||
|         return; |         return; | ||||||
|     } |     } | ||||||
|  |  | ||||||
| @@ -45,20 +45,20 @@ eventService.subscribe([eventService.ENTITY_CHANGED, eventService.ENTITY_DELETED | |||||||
|         const {noteId} = entity; |         const {noteId} = entity; | ||||||
|  |  | ||||||
|         if (entity.isDeleted) { |         if (entity.isDeleted) { | ||||||
|             delete noteCache.notes[noteId]; |             delete becca.notes[noteId]; | ||||||
|         } |         } | ||||||
|         else if (noteId in noteCache.notes) { |         else if (noteId in becca.notes) { | ||||||
|             noteCache.notes[noteId].update(entity); |             becca.notes[noteId].update(entity); | ||||||
|         } |         } | ||||||
|         else { |         else { | ||||||
|             const note = new Note(noteCache, entity); |             const note = new Note(becca, entity); | ||||||
|  |  | ||||||
|             note.decrypt(); |             note.decrypt(); | ||||||
|         } |         } | ||||||
|     } |     } | ||||||
|     else if (entityName === 'branches') { |     else if (entityName === 'branches') { | ||||||
|         const {branchId, noteId, parentNoteId} = entity; |         const {branchId, noteId, parentNoteId} = entity; | ||||||
|         const childNote = noteCache.notes[noteId]; |         const childNote = becca.notes[noteId]; | ||||||
|  |  | ||||||
|         if (entity.isDeleted) { |         if (entity.isDeleted) { | ||||||
|             if (childNote) { |             if (childNote) { | ||||||
| @@ -70,26 +70,26 @@ eventService.subscribe([eventService.ENTITY_CHANGED, eventService.ENTITY_DELETED | |||||||
|                 } |                 } | ||||||
|             } |             } | ||||||
|  |  | ||||||
|             const parentNote = noteCache.notes[parentNoteId]; |             const parentNote = becca.notes[parentNoteId]; | ||||||
|  |  | ||||||
|             if (parentNote) { |             if (parentNote) { | ||||||
|                 parentNote.children = parentNote.children.filter(child => child.noteId !== noteId); |                 parentNote.children = parentNote.children.filter(child => child.noteId !== noteId); | ||||||
|             } |             } | ||||||
|  |  | ||||||
|             delete noteCache.childParentToBranch[`${noteId}-${parentNoteId}`]; |             delete becca.childParentToBranch[`${noteId}-${parentNoteId}`]; | ||||||
|             delete noteCache.branches[branchId]; |             delete becca.branches[branchId]; | ||||||
|         } |         } | ||||||
|         else if (branchId in noteCache.branches) { |         else if (branchId in becca.branches) { | ||||||
|             // only relevant properties which can change in a branch are prefix and isExpanded |             // only relevant properties which can change in a branch are prefix and isExpanded | ||||||
|             noteCache.branches[branchId].prefix = entity.prefix; |             becca.branches[branchId].prefix = entity.prefix; | ||||||
|             noteCache.branches[branchId].isExpanded = entity.isExpanded; |             becca.branches[branchId].isExpanded = entity.isExpanded; | ||||||
|  |  | ||||||
|             if (childNote) { |             if (childNote) { | ||||||
|                 childNote.flatTextCache = null; |                 childNote.flatTextCache = null; | ||||||
|             } |             } | ||||||
|         } |         } | ||||||
|         else { |         else { | ||||||
|             noteCache.branches[branchId] = new Branch(noteCache, entity); |             becca.branches[branchId] = new Branch(becca, entity); | ||||||
|  |  | ||||||
|             if (childNote) { |             if (childNote) { | ||||||
|                 childNote.resortParents(); |                 childNote.resortParents(); | ||||||
| @@ -98,8 +98,8 @@ eventService.subscribe([eventService.ENTITY_CHANGED, eventService.ENTITY_DELETED | |||||||
|     } |     } | ||||||
|     else if (entityName === 'attributes') { |     else if (entityName === 'attributes') { | ||||||
|         const {attributeId, noteId} = entity; |         const {attributeId, noteId} = entity; | ||||||
|         const note = noteCache.notes[noteId]; |         const note = becca.notes[noteId]; | ||||||
|         const attr = noteCache.attributes[attributeId]; |         const attr = becca.attributes[attributeId]; | ||||||
|  |  | ||||||
|         if (entity.isDeleted) { |         if (entity.isDeleted) { | ||||||
|             if (note && attr) { |             if (note && attr) { | ||||||
| @@ -119,18 +119,18 @@ eventService.subscribe([eventService.ENTITY_CHANGED, eventService.ENTITY_DELETED | |||||||
|                 } |                 } | ||||||
|             } |             } | ||||||
|  |  | ||||||
|             delete noteCache.attributes[attributeId]; |             delete becca.attributes[attributeId]; | ||||||
|  |  | ||||||
|             if (attr) { |             if (attr) { | ||||||
|                 const key = `${attr.type}-${attr.name.toLowerCase()}`; |                 const key = `${attr.type}-${attr.name.toLowerCase()}`; | ||||||
|  |  | ||||||
|                 if (key in noteCache.attributeIndex) { |                 if (key in becca.attributeIndex) { | ||||||
|                     noteCache.attributeIndex[key] = noteCache.attributeIndex[key].filter(attr => attr.attributeId !== attributeId); |                     becca.attributeIndex[key] = becca.attributeIndex[key].filter(attr => attr.attributeId !== attributeId); | ||||||
|                 } |                 } | ||||||
|             } |             } | ||||||
|         } |         } | ||||||
|         else if (attributeId in noteCache.attributes) { |         else if (attributeId in becca.attributes) { | ||||||
|             const attr = noteCache.attributes[attributeId]; |             const attr = becca.attributes[attributeId]; | ||||||
|  |  | ||||||
|             // attr name and isInheritable are immutable |             // attr name and isInheritable are immutable | ||||||
|             attr.value = entity.value; |             attr.value = entity.value; | ||||||
| @@ -143,7 +143,7 @@ eventService.subscribe([eventService.ENTITY_CHANGED, eventService.ENTITY_DELETED | |||||||
|             } |             } | ||||||
|         } |         } | ||||||
|         else { |         else { | ||||||
|             const attr = new Attribute(noteCache, entity); |             const attr = new Attribute(becca, entity); | ||||||
|  |  | ||||||
|             if (note) { |             if (note) { | ||||||
|                 if (attr.isAffectingSubtree || note.isTemplate) { |                 if (attr.isAffectingSubtree || note.isTemplate) { | ||||||
| @@ -159,7 +159,7 @@ eventService.subscribe([eventService.ENTITY_CHANGED, eventService.ENTITY_DELETED | |||||||
|         const parentNoteIds = new Set(); |         const parentNoteIds = new Set(); | ||||||
|  |  | ||||||
|         for (const branchId in entity) { |         for (const branchId in entity) { | ||||||
|             const branch = noteCache.branches[branchId]; |             const branch = becca.branches[branchId]; | ||||||
|  |  | ||||||
|             if (branch) { |             if (branch) { | ||||||
|                 branch.notePosition = entity[branchId]; |                 branch.notePosition = entity[branchId]; | ||||||
| @@ -172,7 +172,7 @@ eventService.subscribe([eventService.ENTITY_CHANGED, eventService.ENTITY_DELETED | |||||||
|  |  | ||||||
| eventService.subscribe(eventService.ENTER_PROTECTED_SESSION, () => { | eventService.subscribe(eventService.ENTER_PROTECTED_SESSION, () => { | ||||||
|     try { |     try { | ||||||
|         noteCache.decryptProtectedNotes(); |         becca.decryptProtectedNotes(); | ||||||
|     } |     } | ||||||
|     catch (e) { |     catch (e) { | ||||||
|         log.error(`Could not decrypt protected notes: ${e.message} ${e.stack}`); |         log.error(`Could not decrypt protected notes: ${e.message} ${e.stack}`); | ||||||
|   | |||||||
| @@ -1,20 +1,20 @@ | |||||||
| "use strict"; | "use strict"; | ||||||
|  |  | ||||||
| const noteCache = require('./note_cache'); | const becca = require('./note_cache'); | ||||||
| const cls = require('../cls'); | const cls = require('../cls'); | ||||||
| const protectedSessionService = require('../protected_session'); | const protectedSessionService = require('../protected_session'); | ||||||
| const log = require('../log'); | const log = require('../log'); | ||||||
|  |  | ||||||
| function isNotePathArchived(notePath) { | function isNotePathArchived(notePath) { | ||||||
|     const noteId = notePath[notePath.length - 1]; |     const noteId = notePath[notePath.length - 1]; | ||||||
|     const note = noteCache.notes[noteId]; |     const note = becca.notes[noteId]; | ||||||
|  |  | ||||||
|     if (note.isArchived) { |     if (note.isArchived) { | ||||||
|         return true; |         return true; | ||||||
|     } |     } | ||||||
|  |  | ||||||
|     for (let i = 0; i < notePath.length - 1; i++) { |     for (let i = 0; i < notePath.length - 1; i++) { | ||||||
|         const note = noteCache.notes[notePath[i]]; |         const note = becca.notes[notePath[i]]; | ||||||
|  |  | ||||||
|         // this is going through parents so archived must be inheritable |         // this is going through parents so archived must be inheritable | ||||||
|         if (note.hasInheritableOwnedArchivedLabel) { |         if (note.hasInheritableOwnedArchivedLabel) { | ||||||
| @@ -47,7 +47,7 @@ function isInAncestor(noteId, ancestorNoteId) { | |||||||
|         return true; |         return true; | ||||||
|     } |     } | ||||||
|  |  | ||||||
|     const note = noteCache.notes[noteId]; |     const note = becca.notes[noteId]; | ||||||
|  |  | ||||||
|     if (!note) { |     if (!note) { | ||||||
|         return false; |         return false; | ||||||
| @@ -63,8 +63,8 @@ function isInAncestor(noteId, ancestorNoteId) { | |||||||
| } | } | ||||||
|  |  | ||||||
| function getNoteTitle(childNoteId, parentNoteId) { | function getNoteTitle(childNoteId, parentNoteId) { | ||||||
|     const childNote = noteCache.notes[childNoteId]; |     const childNote = becca.notes[childNoteId]; | ||||||
|     const parentNote = noteCache.notes[parentNoteId]; |     const parentNote = becca.notes[parentNoteId]; | ||||||
|  |  | ||||||
|     if (!childNote) { |     if (!childNote) { | ||||||
|         log.info(`Cannot find note in cache for noteId ${childNoteId}`); |         log.info(`Cannot find note in cache for noteId ${childNoteId}`); | ||||||
| @@ -80,7 +80,7 @@ function getNoteTitle(childNoteId, parentNoteId) { | |||||||
|         title = childNote.title; |         title = childNote.title; | ||||||
|     } |     } | ||||||
|  |  | ||||||
|     const branch = parentNote ? noteCache.getBranch(childNote.noteId, parentNote.noteId) : null; |     const branch = parentNote ? becca.getBranch(childNote.noteId, parentNote.noteId) : null; | ||||||
|  |  | ||||||
|     return ((branch && branch.prefix) ? `${branch.prefix} - ` : '') + title; |     return ((branch && branch.prefix) ? `${branch.prefix} - ` : '') + title; | ||||||
| } | } | ||||||
| @@ -160,7 +160,7 @@ function getSomePathInner(note, path, respectHoistng) { | |||||||
| } | } | ||||||
|  |  | ||||||
| function getNotePath(noteId) { | function getNotePath(noteId) { | ||||||
|     const note = noteCache.notes[noteId]; |     const note = becca.notes[noteId]; | ||||||
|  |  | ||||||
|     if (!note) { |     if (!note) { | ||||||
|         console.trace(`Cannot find note ${noteId} in cache.`); |         console.trace(`Cannot find note ${noteId} in cache.`); | ||||||
| @@ -175,7 +175,7 @@ function getNotePath(noteId) { | |||||||
|  |  | ||||||
|         return { |         return { | ||||||
|             noteId: noteId, |             noteId: noteId, | ||||||
|             branchId: noteCache.getBranch(noteId, parentNote.noteId).branchId, |             branchId: becca.getBranch(noteId, parentNote.noteId).branchId, | ||||||
|             title: noteTitle, |             title: noteTitle, | ||||||
|             notePath: retPath, |             notePath: retPath, | ||||||
|             path: retPath.join('/') |             path: retPath.join('/') | ||||||
|   | |||||||
| @@ -1,6 +1,6 @@ | |||||||
| const noteCache = require('./note_cache'); | const becca = require('./note_cache'); | ||||||
| const log = require('../log'); | const log = require('../log'); | ||||||
| const noteCacheService = require('./note_cache_service.js'); | const beccaService = require('./note_cache_service.js'); | ||||||
| const dateUtils = require('../date_utils'); | const dateUtils = require('../date_utils'); | ||||||
| const repository = require('../repository'); | const repository = require('../repository'); | ||||||
| const { JSDOM } = require("jsdom"); | const { JSDOM } = require("jsdom"); | ||||||
| @@ -231,7 +231,7 @@ async function findSimilarNotes(noteId) { | |||||||
|     const results = []; |     const results = []; | ||||||
|     let i = 0; |     let i = 0; | ||||||
|  |  | ||||||
|     const baseNote = noteCache.notes[noteId]; |     const baseNote = becca.notes[noteId]; | ||||||
|  |  | ||||||
|     if (!baseNote || !baseNote.utcDateCreated) { |     if (!baseNote || !baseNote.utcDateCreated) { | ||||||
|         return []; |         return []; | ||||||
| @@ -394,7 +394,7 @@ async function findSimilarNotes(noteId) { | |||||||
|         return score; |         return score; | ||||||
|     } |     } | ||||||
|  |  | ||||||
|     for (const candidateNote of Object.values(noteCache.notes)) { |     for (const candidateNote of Object.values(becca.notes)) { | ||||||
|         if (candidateNote.noteId === baseNote.noteId |         if (candidateNote.noteId === baseNote.noteId | ||||||
|             || hasConnectingRelation(candidateNote, baseNote) |             || hasConnectingRelation(candidateNote, baseNote) | ||||||
|             || hasConnectingRelation(baseNote, candidateNote)) { |             || hasConnectingRelation(baseNote, candidateNote)) { | ||||||
| @@ -404,14 +404,14 @@ async function findSimilarNotes(noteId) { | |||||||
|         let score = computeScore(candidateNote); |         let score = computeScore(candidateNote); | ||||||
|  |  | ||||||
|         if (score >= 1.5) { |         if (score >= 1.5) { | ||||||
|             const notePath = noteCacheService.getSomePath(candidateNote); |             const notePath = beccaService.getSomePath(candidateNote); | ||||||
|  |  | ||||||
|             // this takes care of note hoisting |             // this takes care of note hoisting | ||||||
|             if (!notePath) { |             if (!notePath) { | ||||||
|                 return; |                 return; | ||||||
|             } |             } | ||||||
|  |  | ||||||
|             if (noteCacheService.isNotePathArchived(notePath)) { |             if (beccaService.isNotePathArchived(notePath)) { | ||||||
|                 score -= 0.5; // archived penalization |                 score -= 0.5; // archived penalization | ||||||
|             } |             } | ||||||
|  |  | ||||||
| @@ -432,7 +432,7 @@ async function findSimilarNotes(noteId) { | |||||||
|  |  | ||||||
|         if (results.length >= 1) { |         if (results.length >= 1) { | ||||||
|             for (const {noteId} of results) { |             for (const {noteId} of results) { | ||||||
|                 const note = noteCache.notes[noteId]; |                 const note = becca.notes[noteId]; | ||||||
|  |  | ||||||
|                 console.log("NOTE", note.pojo); |                 console.log("NOTE", note.pojo); | ||||||
|  |  | ||||||
|   | |||||||
| @@ -3,7 +3,7 @@ | |||||||
| const Expression = require('./expression'); | const Expression = require('./expression'); | ||||||
| const NoteSet = require('../note_set'); | const NoteSet = require('../note_set'); | ||||||
| const log = require('../../log'); | const log = require('../../log'); | ||||||
| const noteCache = require('../../note_cache/note_cache'); | const becca = require('../../note_cache/note_cache'); | ||||||
|  |  | ||||||
| class AncestorExp extends Expression { | class AncestorExp extends Expression { | ||||||
|     constructor(ancestorNoteId, ancestorDepth) { |     constructor(ancestorNoteId, ancestorDepth) { | ||||||
| @@ -15,7 +15,7 @@ class AncestorExp extends Expression { | |||||||
|     } |     } | ||||||
|  |  | ||||||
|     execute(inputNoteSet, executionContext) { |     execute(inputNoteSet, executionContext) { | ||||||
|         const ancestorNote = noteCache.notes[this.ancestorNoteId]; |         const ancestorNote = becca.notes[this.ancestorNoteId]; | ||||||
|  |  | ||||||
|         if (!ancestorNote) { |         if (!ancestorNote) { | ||||||
|             log.error(`Subtree note '${this.ancestorNoteId}' was not not found.`); |             log.error(`Subtree note '${this.ancestorNoteId}' was not not found.`); | ||||||
|   | |||||||
| @@ -1,7 +1,7 @@ | |||||||
| "use strict"; | "use strict"; | ||||||
|  |  | ||||||
| const NoteSet = require('../note_set'); | const NoteSet = require('../note_set'); | ||||||
| const noteCache = require('../../note_cache/note_cache'); | const becca = require('../../note_cache/note_cache'); | ||||||
| const Expression = require('./expression'); | const Expression = require('./expression'); | ||||||
|  |  | ||||||
| class AttributeExistsExp extends Expression { | class AttributeExistsExp extends Expression { | ||||||
| @@ -15,8 +15,8 @@ class AttributeExistsExp extends Expression { | |||||||
|  |  | ||||||
|     execute(inputNoteSet) { |     execute(inputNoteSet) { | ||||||
|         const attrs = this.prefixMatch |         const attrs = this.prefixMatch | ||||||
|             ? noteCache.findAttributesWithPrefix(this.attributeType, this.attributeName) |             ? becca.findAttributesWithPrefix(this.attributeType, this.attributeName) | ||||||
|             : noteCache.findAttributes(this.attributeType, this.attributeName); |             : becca.findAttributes(this.attributeType, this.attributeName); | ||||||
|  |  | ||||||
|         const resultNoteSet = new NoteSet(); |         const resultNoteSet = new NoteSet(); | ||||||
|  |  | ||||||
|   | |||||||
| @@ -2,7 +2,7 @@ | |||||||
|  |  | ||||||
| const Expression = require('./expression'); | const Expression = require('./expression'); | ||||||
| const NoteSet = require('../note_set'); | const NoteSet = require('../note_set'); | ||||||
| const noteCache = require('../../note_cache/note_cache'); | const becca = require('../../note_cache/note_cache'); | ||||||
|  |  | ||||||
| class DescendantOfExp extends Expression { | class DescendantOfExp extends Expression { | ||||||
|     constructor(subExpression) { |     constructor(subExpression) { | ||||||
| @@ -12,7 +12,7 @@ class DescendantOfExp extends Expression { | |||||||
|     } |     } | ||||||
|  |  | ||||||
|     execute(inputNoteSet, executionContext) { |     execute(inputNoteSet, executionContext) { | ||||||
|         const subInputNoteSet = new NoteSet(Object.values(noteCache.notes)); |         const subInputNoteSet = new NoteSet(Object.values(becca.notes)); | ||||||
|         const subResNoteSet = this.subExpression.execute(subInputNoteSet, executionContext); |         const subResNoteSet = this.subExpression.execute(subInputNoteSet, executionContext); | ||||||
|  |  | ||||||
|         const subTreeNoteSet = new NoteSet(); |         const subTreeNoteSet = new NoteSet(); | ||||||
|   | |||||||
| @@ -2,7 +2,7 @@ | |||||||
|  |  | ||||||
| const Expression = require('./expression'); | const Expression = require('./expression'); | ||||||
| const NoteSet = require('../note_set'); | const NoteSet = require('../note_set'); | ||||||
| const noteCache = require('../../note_cache/note_cache'); | const becca = require('../../note_cache/note_cache'); | ||||||
|  |  | ||||||
| class LabelComparisonExp extends Expression { | class LabelComparisonExp extends Expression { | ||||||
|     constructor(attributeType, attributeName, comparator) { |     constructor(attributeType, attributeName, comparator) { | ||||||
| @@ -14,7 +14,7 @@ class LabelComparisonExp extends Expression { | |||||||
|     } |     } | ||||||
|  |  | ||||||
|     execute(inputNoteSet) { |     execute(inputNoteSet) { | ||||||
|         const attrs = noteCache.findAttributes(this.attributeType, this.attributeName); |         const attrs = becca.findAttributes(this.attributeType, this.attributeName); | ||||||
|         const resultNoteSet = new NoteSet(); |         const resultNoteSet = new NoteSet(); | ||||||
|  |  | ||||||
|         for (const attr of attrs) { |         for (const attr of attrs) { | ||||||
|   | |||||||
| @@ -2,9 +2,9 @@ | |||||||
|  |  | ||||||
| const Expression = require('./expression'); | const Expression = require('./expression'); | ||||||
| const NoteSet = require('../note_set'); | const NoteSet = require('../note_set'); | ||||||
| const noteCache = require('../../note_cache/note_cache'); | const becca = require('../../note_cache/note_cache'); | ||||||
|  |  | ||||||
| class NoteCacheFlatTextExp extends Expression { | class BeccaFlatTextExp extends Expression { | ||||||
|     constructor(tokens) { |     constructor(tokens) { | ||||||
|         super(); |         super(); | ||||||
|  |  | ||||||
| @@ -13,18 +13,18 @@ class NoteCacheFlatTextExp extends Expression { | |||||||
|  |  | ||||||
|     execute(inputNoteSet, executionContext) { |     execute(inputNoteSet, executionContext) { | ||||||
|         // has deps on SQL which breaks unit test so needs to be dynamically required |         // has deps on SQL which breaks unit test so needs to be dynamically required | ||||||
|         const noteCacheService = require('../../note_cache/note_cache_service'); |         const beccaService = require('../../note_cache/note_cache_service'); | ||||||
|         const resultNoteSet = new NoteSet(); |         const resultNoteSet = new NoteSet(); | ||||||
|  |  | ||||||
|         function searchDownThePath(note, tokens, path) { |         function searchDownThePath(note, tokens, path) { | ||||||
|             if (tokens.length === 0) { |             if (tokens.length === 0) { | ||||||
|                 const retPath = noteCacheService.getSomePath(note, path); |                 const retPath = beccaService.getSomePath(note, path); | ||||||
|  |  | ||||||
|                 if (retPath) { |                 if (retPath) { | ||||||
|                     const noteId = retPath[retPath.length - 1]; |                     const noteId = retPath[retPath.length - 1]; | ||||||
|                     executionContext.noteIdToNotePath[noteId] = retPath; |                     executionContext.noteIdToNotePath[noteId] = retPath; | ||||||
|  |  | ||||||
|                     resultNoteSet.add(noteCache.notes[noteId]); |                     resultNoteSet.add(becca.notes[noteId]); | ||||||
|                 } |                 } | ||||||
|  |  | ||||||
|                 return; |                 return; | ||||||
| @@ -52,7 +52,7 @@ class NoteCacheFlatTextExp extends Expression { | |||||||
|             } |             } | ||||||
|  |  | ||||||
|             for (const parentNote of note.parents) { |             for (const parentNote of note.parents) { | ||||||
|                 const title = noteCacheService.getNoteTitle(note.noteId, parentNote.noteId).toLowerCase(); |                 const title = beccaService.getNoteTitle(note.noteId, parentNote.noteId).toLowerCase(); | ||||||
|                 const foundTokens = foundAttrTokens.slice(); |                 const foundTokens = foundAttrTokens.slice(); | ||||||
|  |  | ||||||
|                 for (const token of tokens) { |                 for (const token of tokens) { | ||||||
| @@ -98,7 +98,7 @@ class NoteCacheFlatTextExp extends Expression { | |||||||
|             } |             } | ||||||
|  |  | ||||||
|             for (const parentNote of note.parents) { |             for (const parentNote of note.parents) { | ||||||
|                 const title = noteCacheService.getNoteTitle(note.noteId, parentNote.noteId).toLowerCase(); |                 const title = beccaService.getNoteTitle(note.noteId, parentNote.noteId).toLowerCase(); | ||||||
|                 const foundTokens = foundAttrTokens.slice(); |                 const foundTokens = foundAttrTokens.slice(); | ||||||
|  |  | ||||||
|                 for (const token of this.tokens) { |                 for (const token of this.tokens) { | ||||||
| @@ -140,4 +140,4 @@ class NoteCacheFlatTextExp extends Expression { | |||||||
|     } |     } | ||||||
| } | } | ||||||
|  |  | ||||||
| module.exports = NoteCacheFlatTextExp; | module.exports = BeccaFlatTextExp; | ||||||
|   | |||||||
| @@ -3,7 +3,7 @@ | |||||||
| const Expression = require('./expression'); | const Expression = require('./expression'); | ||||||
| const NoteSet = require('../note_set'); | const NoteSet = require('../note_set'); | ||||||
| const log = require('../../log'); | const log = require('../../log'); | ||||||
| const noteCache = require('../../note_cache/note_cache'); | const becca = require('../../note_cache/note_cache'); | ||||||
| const protectedSessionService = require('../../protected_session'); | const protectedSessionService = require('../../protected_session'); | ||||||
| const striptags = require('striptags'); | const striptags = require('striptags'); | ||||||
|  |  | ||||||
| @@ -33,7 +33,7 @@ class NoteContentProtectedFulltextExp extends Expression { | |||||||
|                 FROM notes JOIN note_contents USING (noteId)  |                 FROM notes JOIN note_contents USING (noteId)  | ||||||
|                 WHERE type IN ('text', 'code') AND isDeleted = 0 AND isProtected = 1`)) { |                 WHERE type IN ('text', 'code') AND isDeleted = 0 AND isProtected = 1`)) { | ||||||
|  |  | ||||||
|             if (!inputNoteSet.hasNoteId(noteId) || !(noteId in noteCache.notes)) { |             if (!inputNoteSet.hasNoteId(noteId) || !(noteId in becca.notes)) { | ||||||
|                 continue; |                 continue; | ||||||
|             } |             } | ||||||
|  |  | ||||||
| @@ -56,7 +56,7 @@ class NoteContentProtectedFulltextExp extends Expression { | |||||||
|             } |             } | ||||||
|  |  | ||||||
|             if (!this.tokens.find(token => !content.includes(token))) { |             if (!this.tokens.find(token => !content.includes(token))) { | ||||||
|                 resultNoteSet.add(noteCache.notes[noteId]); |                 resultNoteSet.add(becca.notes[noteId]); | ||||||
|             } |             } | ||||||
|         } |         } | ||||||
|  |  | ||||||
|   | |||||||
| @@ -2,7 +2,7 @@ | |||||||
|  |  | ||||||
| const Expression = require('./expression'); | const Expression = require('./expression'); | ||||||
| const NoteSet = require('../note_set'); | const NoteSet = require('../note_set'); | ||||||
| const noteCache = require('../../note_cache/note_cache'); | const becca = require('../../note_cache/note_cache'); | ||||||
| const striptags = require('striptags'); | const striptags = require('striptags'); | ||||||
|  |  | ||||||
| class NoteContentUnprotectedFulltextExp extends Expression { | class NoteContentUnprotectedFulltextExp extends Expression { | ||||||
| @@ -27,7 +27,7 @@ class NoteContentUnprotectedFulltextExp extends Expression { | |||||||
|                 FROM notes JOIN note_contents USING (noteId)  |                 FROM notes JOIN note_contents USING (noteId)  | ||||||
|                 WHERE type IN ('text', 'code') AND isDeleted = 0 AND isProtected = 0`)) { |                 WHERE type IN ('text', 'code') AND isDeleted = 0 AND isProtected = 0`)) { | ||||||
|  |  | ||||||
|             if (!inputNoteSet.hasNoteId(noteId) || !(noteId in noteCache.notes)) { |             if (!inputNoteSet.hasNoteId(noteId) || !(noteId in becca.notes)) { | ||||||
|                 continue; |                 continue; | ||||||
|             } |             } | ||||||
|  |  | ||||||
| @@ -42,7 +42,7 @@ class NoteContentUnprotectedFulltextExp extends Expression { | |||||||
|             } |             } | ||||||
|  |  | ||||||
|             if (!this.tokens.find(token => !content.includes(token))) { |             if (!this.tokens.find(token => !content.includes(token))) { | ||||||
|                 resultNoteSet.add(noteCache.notes[noteId]); |                 resultNoteSet.add(becca.notes[noteId]); | ||||||
|             } |             } | ||||||
|         } |         } | ||||||
|  |  | ||||||
|   | |||||||
| @@ -2,7 +2,7 @@ | |||||||
|  |  | ||||||
| const Expression = require('./expression'); | const Expression = require('./expression'); | ||||||
| const NoteSet = require('../note_set'); | const NoteSet = require('../note_set'); | ||||||
| const noteCache = require('../../note_cache/note_cache'); | const becca = require('../../note_cache/note_cache'); | ||||||
|  |  | ||||||
| class RelationWhereExp extends Expression { | class RelationWhereExp extends Expression { | ||||||
|     constructor(relationName, subExpression) { |     constructor(relationName, subExpression) { | ||||||
| @@ -15,7 +15,7 @@ class RelationWhereExp extends Expression { | |||||||
|     execute(inputNoteSet, executionContext) { |     execute(inputNoteSet, executionContext) { | ||||||
|         const candidateNoteSet = new NoteSet(); |         const candidateNoteSet = new NoteSet(); | ||||||
|  |  | ||||||
|         for (const attr of noteCache.findAttributes('relation', this.relationName)) { |         for (const attr of becca.findAttributes('relation', this.relationName)) { | ||||||
|             const note = attr.note; |             const note = attr.note; | ||||||
|  |  | ||||||
|             if (inputNoteSet.hasNoteId(note.noteId) && attr.targetNote) { |             if (inputNoteSet.hasNoteId(note.noteId) && attr.targetNote) { | ||||||
|   | |||||||
| @@ -21,7 +21,7 @@ class SearchContext { | |||||||
|         this.fuzzyAttributeSearch = !!params.fuzzyAttributeSearch; |         this.fuzzyAttributeSearch = !!params.fuzzyAttributeSearch; | ||||||
|         this.highlightedTokens = []; |         this.highlightedTokens = []; | ||||||
|         this.originalQuery = ""; |         this.originalQuery = ""; | ||||||
|         // if true, note cache does not have (up-to-date) information needed to process the query |         // if true, becca does not have (up-to-date) information needed to process the query | ||||||
|         // and some extra data needs to be loaded before executing |         // and some extra data needs to be loaded before executing | ||||||
|         this.dbLoadNeeded = false; |         this.dbLoadNeeded = false; | ||||||
|         this.error = null; |         this.error = null; | ||||||
|   | |||||||
| @@ -1,11 +1,11 @@ | |||||||
| "use strict"; | "use strict"; | ||||||
|  |  | ||||||
| const noteCacheService = require('../note_cache/note_cache_service'); | const beccaService = require('../note_cache/note_cache_service'); | ||||||
|  |  | ||||||
| class SearchResult { | class SearchResult { | ||||||
|     constructor(notePathArray) { |     constructor(notePathArray) { | ||||||
|         this.notePathArray = notePathArray; |         this.notePathArray = notePathArray; | ||||||
|         this.notePathTitle = noteCacheService.getNoteTitleForPath(notePathArray); |         this.notePathTitle = beccaService.getNoteTitleForPath(notePathArray); | ||||||
|     } |     } | ||||||
|  |  | ||||||
|     get notePath() { |     get notePath() { | ||||||
|   | |||||||
| @@ -11,7 +11,7 @@ const RelationWhereExp = require('../expressions/relation_where.js'); | |||||||
| const PropertyComparisonExp = require('../expressions/property_comparison.js'); | const PropertyComparisonExp = require('../expressions/property_comparison.js'); | ||||||
| const AttributeExistsExp = require('../expressions/attribute_exists.js'); | const AttributeExistsExp = require('../expressions/attribute_exists.js'); | ||||||
| const LabelComparisonExp = require('../expressions/label_comparison.js'); | const LabelComparisonExp = require('../expressions/label_comparison.js'); | ||||||
| const NoteCacheFlatTextExp = require('../expressions/note_cache_flat_text.js'); | const BeccaFlatTextExp = require('../expressions/note_cache_flat_text.js'); | ||||||
| const NoteContentProtectedFulltextExp = require('../expressions/note_content_protected_fulltext.js'); | const NoteContentProtectedFulltextExp = require('../expressions/note_content_protected_fulltext.js'); | ||||||
| const NoteContentUnprotectedFulltextExp = require('../expressions/note_content_unprotected_fulltext.js'); | const NoteContentUnprotectedFulltextExp = require('../expressions/note_content_unprotected_fulltext.js'); | ||||||
| const OrderByAndLimitExp = require('../expressions/order_by_and_limit.js'); | const OrderByAndLimitExp = require('../expressions/order_by_and_limit.js'); | ||||||
| @@ -30,13 +30,13 @@ function getFulltext(tokens, searchContext) { | |||||||
|  |  | ||||||
|     if (!searchContext.fastSearch) { |     if (!searchContext.fastSearch) { | ||||||
|         return new OrExp([ |         return new OrExp([ | ||||||
|             new NoteCacheFlatTextExp(tokens), |             new BeccaFlatTextExp(tokens), | ||||||
|             new NoteContentProtectedFulltextExp('*=*', tokens), |             new NoteContentProtectedFulltextExp('*=*', tokens), | ||||||
|             new NoteContentUnprotectedFulltextExp('*=*', tokens) |             new NoteContentUnprotectedFulltextExp('*=*', tokens) | ||||||
|         ]); |         ]); | ||||||
|     } |     } | ||||||
|     else { |     else { | ||||||
|         return new NoteCacheFlatTextExp(tokens); |         return new BeccaFlatTextExp(tokens); | ||||||
|     } |     } | ||||||
| } | } | ||||||
|  |  | ||||||
|   | |||||||
| @@ -6,18 +6,18 @@ const parse = require('./parse.js'); | |||||||
| const NoteSet = require("../note_set.js"); | const NoteSet = require("../note_set.js"); | ||||||
| const SearchResult = require("../search_result.js"); | const SearchResult = require("../search_result.js"); | ||||||
| const SearchContext = require("../search_context.js"); | const SearchContext = require("../search_context.js"); | ||||||
| const noteCache = require('../../note_cache/note_cache.js'); | const becca = require('../../note_cache/note_cache.js'); | ||||||
| const noteCacheService = require('../../note_cache/note_cache_service.js'); | const beccaService = require('../../note_cache/note_cache_service.js'); | ||||||
| const utils = require('../../utils.js'); | const utils = require('../../utils.js'); | ||||||
| const log = require('../../log.js'); | const log = require('../../log.js'); | ||||||
|  |  | ||||||
| function loadNeededInfoFromDatabase() { | function loadNeededInfoFromDatabase() { | ||||||
|     const sql = require('../../sql.js'); |     const sql = require('../../sql.js'); | ||||||
|  |  | ||||||
|     for (const noteId in noteCache.notes) { |     for (const noteId in becca.notes) { | ||||||
|         noteCache.notes[noteId].contentSize = 0; |         becca.notes[noteId].contentSize = 0; | ||||||
|         noteCache.notes[noteId].noteSize = 0; |         becca.notes[noteId].noteSize = 0; | ||||||
|         noteCache.notes[noteId].revisionCount = 0; |         becca.notes[noteId].revisionCount = 0; | ||||||
|     } |     } | ||||||
|  |  | ||||||
|     const noteContentLengths = sql.getRows(` |     const noteContentLengths = sql.getRows(` | ||||||
| @@ -29,13 +29,13 @@ function loadNeededInfoFromDatabase() { | |||||||
|         WHERE notes.isDeleted = 0`); |         WHERE notes.isDeleted = 0`); | ||||||
|  |  | ||||||
|     for (const {noteId, length} of noteContentLengths) { |     for (const {noteId, length} of noteContentLengths) { | ||||||
|         if (!(noteId in noteCache.notes)) { |         if (!(noteId in becca.notes)) { | ||||||
|             log.error(`Note ${noteId} not found in note cache.`); |             log.error(`Note ${noteId} not found in becca.`); | ||||||
|             continue; |             continue; | ||||||
|         } |         } | ||||||
|  |  | ||||||
|         noteCache.notes[noteId].contentSize = length; |         becca.notes[noteId].contentSize = length; | ||||||
|         noteCache.notes[noteId].noteSize = length; |         becca.notes[noteId].noteSize = length; | ||||||
|     } |     } | ||||||
|  |  | ||||||
|     const noteRevisionContentLengths = sql.getRows(` |     const noteRevisionContentLengths = sql.getRows(` | ||||||
| @@ -48,13 +48,13 @@ function loadNeededInfoFromDatabase() { | |||||||
|         WHERE notes.isDeleted = 0`); |         WHERE notes.isDeleted = 0`); | ||||||
|  |  | ||||||
|     for (const {noteId, length} of noteRevisionContentLengths) { |     for (const {noteId, length} of noteRevisionContentLengths) { | ||||||
|         if (!(noteId in noteCache.notes)) { |         if (!(noteId in becca.notes)) { | ||||||
|             log.error(`Note ${noteId} not found in note cache.`); |             log.error(`Note ${noteId} not found in becca.`); | ||||||
|             continue; |             continue; | ||||||
|         } |         } | ||||||
|  |  | ||||||
|         noteCache.notes[noteId].noteSize += length; |         becca.notes[noteId].noteSize += length; | ||||||
|         noteCache.notes[noteId].revisionCount++; |         becca.notes[noteId].revisionCount++; | ||||||
|     } |     } | ||||||
| } | } | ||||||
|  |  | ||||||
| @@ -64,7 +64,7 @@ function loadNeededInfoFromDatabase() { | |||||||
|  * @return {SearchResult[]} |  * @return {SearchResult[]} | ||||||
|  */ |  */ | ||||||
| function findNotesWithExpression(expression, searchContext) { | function findNotesWithExpression(expression, searchContext) { | ||||||
|     let allNotes = Object.values(noteCache.notes); |     let allNotes = Object.values(becca.notes); | ||||||
|  |  | ||||||
|     if (searchContext.dbLoadNeeded) { |     if (searchContext.dbLoadNeeded) { | ||||||
|         loadNeededInfoFromDatabase(); |         loadNeededInfoFromDatabase(); | ||||||
| @@ -84,7 +84,7 @@ function findNotesWithExpression(expression, searchContext) { | |||||||
|  |  | ||||||
|     const searchResults = noteSet.notes |     const searchResults = noteSet.notes | ||||||
|         .map(note => new SearchResult( |         .map(note => new SearchResult( | ||||||
|             executionContext.noteIdToNotePath[note.noteId] || noteCacheService.getSomePath(note) |             executionContext.noteIdToNotePath[note.noteId] || beccaService.getSomePath(note) | ||||||
|         )); |         )); | ||||||
|  |  | ||||||
|     for (const res of searchResults) { |     for (const res of searchResults) { | ||||||
| @@ -174,7 +174,7 @@ function searchNotesForAutocomplete(query) { | |||||||
|     return results.map(result => { |     return results.map(result => { | ||||||
|         return { |         return { | ||||||
|             notePath: result.notePath, |             notePath: result.notePath, | ||||||
|             noteTitle: noteCacheService.getNoteTitle(result.noteId), |             noteTitle: beccaService.getNoteTitle(result.noteId), | ||||||
|             notePathTitle: result.notePathTitle, |             notePathTitle: result.notePathTitle, | ||||||
|             highlightedNotePathTitle: result.highlightedNotePathTitle |             highlightedNotePathTitle: result.highlightedNotePathTitle | ||||||
|         } |         } | ||||||
| @@ -194,7 +194,7 @@ function highlightSearchResults(searchResults, highlightedTokens) { | |||||||
|     highlightedTokens.sort((a, b) => a.length > b.length ? -1 : 1); |     highlightedTokens.sort((a, b) => a.length > b.length ? -1 : 1); | ||||||
|  |  | ||||||
|     for (const result of searchResults) { |     for (const result of searchResults) { | ||||||
|         const note = noteCache.notes[result.noteId]; |         const note = becca.notes[result.noteId]; | ||||||
|  |  | ||||||
|         result.highlightedNotePathTitle = result.notePathTitle.replace('/[<\{\}]/g', ''); |         result.highlightedNotePathTitle = result.notePathTitle.replace('/[<\{\}]/g', ''); | ||||||
|  |  | ||||||
|   | |||||||
| @@ -247,7 +247,7 @@ function transactional(func) { | |||||||
|         const entityChanges = cls.getAndClearEntityChanges(); |         const entityChanges = cls.getAndClearEntityChanges(); | ||||||
|  |  | ||||||
|         if (entityChanges.length > 0) { |         if (entityChanges.length > 0) { | ||||||
|             log.info("Transaction rollback dirtied the note cache, forcing reload."); |             log.info("Transaction rollback dirtied the becca, forcing reload."); | ||||||
|  |  | ||||||
|             require('./note_cache/note_cache_loader').load(); |             require('./note_cache/note_cache_loader').load(); | ||||||
|         } |         } | ||||||
|   | |||||||
| @@ -6,7 +6,7 @@ const repository = require('./repository'); | |||||||
| const Branch = require('../entities/branch'); | const Branch = require('../entities/branch'); | ||||||
| const entityChangesService = require('./entity_changes.js'); | const entityChangesService = require('./entity_changes.js'); | ||||||
| const protectedSessionService = require('./protected_session'); | const protectedSessionService = require('./protected_session'); | ||||||
| const noteCache = require('./note_cache/note_cache'); | const becca = require('./note_cache/note_cache'); | ||||||
|  |  | ||||||
| function getNotes(noteIds) { | function getNotes(noteIds) { | ||||||
|     // we return also deleted notes which have been specifically asked for |     // we return also deleted notes which have been specifically asked for | ||||||
| @@ -140,11 +140,11 @@ function sortNotesByTitle(parentNoteId, foldersFirst = false, reverse = false) { | |||||||
|             sql.execute("UPDATE branches SET notePosition = ? WHERE branchId = ?", |             sql.execute("UPDATE branches SET notePosition = ? WHERE branchId = ?", | ||||||
|                 [position, note.branchId]); |                 [position, note.branchId]); | ||||||
|  |  | ||||||
|             if (note.branchId in noteCache.branches) { |             if (note.branchId in becca.branches) { | ||||||
|                 noteCache.branches[note.branchId].notePosition = position; |                 becca.branches[note.branchId].notePosition = position; | ||||||
|             } |             } | ||||||
|             else { |             else { | ||||||
|                 log.info(`Branch "${note.branchId}" was not found in note cache.`); |                 log.info(`Branch "${note.branchId}" was not found in becca.`); | ||||||
|             } |             } | ||||||
|  |  | ||||||
|             position += 10; |             position += 10; | ||||||
| @@ -172,7 +172,7 @@ function sortNotes(parentNoteId, sortBy, reverse = false) { | |||||||
|             sql.execute("UPDATE branches SET notePosition = ? WHERE branchId = ?", |             sql.execute("UPDATE branches SET notePosition = ? WHERE branchId = ?", | ||||||
|                 [position, branch.branchId]); |                 [position, branch.branchId]); | ||||||
|  |  | ||||||
|             noteCache.branches[branch.branchId].notePosition = position; |             becca.branches[branch.branchId].notePosition = position; | ||||||
|  |  | ||||||
|             position += 10; |             position += 10; | ||||||
|         } |         } | ||||||
|   | |||||||
		Reference in New Issue
	
	Block a user