diff --git a/packages/models/src/Domain/Runtime/Collection/Item/TagItemsIndex.ts b/packages/models/src/Domain/Runtime/Collection/Item/TagItemsIndex.ts index 61e495479..16f651782 100644 --- a/packages/models/src/Domain/Runtime/Collection/Item/TagItemsIndex.ts +++ b/packages/models/src/Domain/Runtime/Collection/Item/TagItemsIndex.ts @@ -1,3 +1,4 @@ +import { isNote } from './../../../Syncable/Note/Note' import { removeFromArray } from '@standardnotes/utils' import { ContentType, Uuid } from '@standardnotes/common' import { isTag, SNTag } from '../../../Syncable/Tag/Tag' @@ -12,6 +13,7 @@ export type TagItemCountChangeObserver = (tagUuid: Uuid | AllNotesUuidSignifier) export class TagItemsIndex implements SNIndex { private tagToItemsMap: Partial>> = {} private allCountableItems = new Set() + private allCountableNotes = new Set() constructor(private collection: ItemCollection, public observers: TagItemCountChangeObserver[] = []) {} @@ -41,6 +43,10 @@ export class TagItemsIndex implements SNIndex { return this.allCountableItems.size } + public allCountableNotesCount(): number { + return this.allCountableNotes.size + } + public countableItemsForTag(tag: SNTag): number { return this.tagToItemsMap[tag.uuid]?.size || 0 } @@ -75,10 +81,19 @@ export class TagItemsIndex implements SNIndex { for (const item of items) { const isCountable = this.isItemCountable(item) + if (isCountable) { this.allCountableItems.add(item.uuid) + + if (isNote(item)) { + this.allCountableNotes.add(item.uuid) + } } else { this.allCountableItems.delete(item.uuid) + + if (isNote(item)) { + this.allCountableNotes.delete(item.uuid) + } } const associatedTagUuids = this.collection.uuidsThatReferenceUuid(item.uuid) diff --git a/packages/snjs/lib/Services/Items/ItemManager.ts b/packages/snjs/lib/Services/Items/ItemManager.ts index 35fd1a69d..4490c39eb 100644 --- a/packages/snjs/lib/Services/Items/ItemManager.ts +++ b/packages/snjs/lib/Services/Items/ItemManager.ts @@ -289,13 +289,13 @@ export class ItemManager } public allCountableNotesCount(): number { - return this.tagItemsIndex.allCountableItemsCount() + return this.tagItemsIndex.allCountableNotesCount() } public countableNotesForTag(tag: Models.SNTag | Models.SmartView): number { if (tag instanceof Models.SmartView) { if (tag.uuid === Models.SystemViewId.AllNotes) { - return this.tagItemsIndex.allCountableItemsCount() + return this.tagItemsIndex.allCountableNotesCount() } throw Error('countableItemsForTag is not meant to be used for smart views.')