refactoring for archived notes handling in note cache

This commit is contained in:
zadam
2020-09-07 00:05:01 +02:00
parent eb4d86f41d
commit 69e36d2677
8 changed files with 22 additions and 29 deletions

View File

@@ -138,12 +138,6 @@ class Note {
return this.hasAttribute('label', 'archived');
}
get isHideInAutocompleteOrArchived() {
return this.attributes.find(attr =>
attr.type === 'label'
&& ["archived", "hideInAutocomplete"].includes(attr.name));
}
get hasInheritableOwnedArchivedLabel() {
return !!this.ownedAttributes.find(attr => attr.type === 'label' && attr.name === 'archived' && attr.isInheritable);
}
@@ -155,20 +149,19 @@ class Note {
}
/**
* @return {string} - returns flattened textual representation of note, prefixes and attributes usable for searching
* This is used for:
* - fast searching
* - note similarity evaluation
*
* @return {string} - returns flattened textual representation of note, prefixes and attributes
*/
get flatText() {
if (!this.flatTextCache) {
if (this.isHideInAutocompleteOrArchived) {
this.flatTextCache = " "; // can't be empty
return this.flatTextCache;
}
this.flatTextCache = this.noteId + ' ' + this.type + ' ' + this.mime;
this.flatTextCache = this.noteId + ' ' + this.type + ' ' + this.mime + ' ';
for (const branch of this.parentBranches) {
if (branch.prefix) {
this.flatTextCache += branch.prefix + ' - ';
this.flatTextCache += branch.prefix + ' ';
}
}
@@ -176,11 +169,13 @@ class Note {
for (const attr of this.attributes) {
// it's best to use space as separator since spaces are filtered from the search string by the tokenization into words
this.flatTextCache += ' ' + (attr.type === 'label' ? '#' : '@') + attr.name;
this.flatTextCache += (attr.type === 'label' ? '#' : '~') + attr.name;
if (attr.value) {
this.flatTextCache += '=' + attr.value;
}
this.flatTextCache += ' ';
}
this.flatTextCache = this.flatTextCache.toLowerCase();