From ae28403f9b0a4a478fb14ec7c5f729c7c862d22a Mon Sep 17 00:00:00 2001 From: Liam O'Brien Date: Fri, 10 Jul 2026 11:53:21 +0100 Subject: [PATCH] New index for querying items in a users synced collection GitOrigin-RevId: aa81ca46cdd238a46a8002d1c991da787c1b9b0f --- ...aryReferences_zotero_collections_index.mjs | 36 +++++++++++++++++++ 1 file changed, 36 insertions(+) create mode 100644 tools/migrations/20260710120000_create_libraryReferences_zotero_collections_index.mjs diff --git a/tools/migrations/20260710120000_create_libraryReferences_zotero_collections_index.mjs b/tools/migrations/20260710120000_create_libraryReferences_zotero_collections_index.mjs new file mode 100644 index 0000000000..a2d52d38cf --- /dev/null +++ b/tools/migrations/20260710120000_create_libraryReferences_zotero_collections_index.mjs @@ -0,0 +1,36 @@ +import Helpers from './lib/helpers.mjs' + +const tags = ['saas'] + +// Supports the moved-out-of-collection diff: for a synced collection, find +// every locally-recorded item whose cached membership includes that +// collection key, projected down to just itemKey/collections (see +// findZoteroCollectionMembership in LibraryReferenceRepository.mts). +const newIndexes = [ + { + key: { + userId: 1, + 'sources.zotero.libraryType': 1, + 'sources.zotero.libraryId': 1, + 'sources.zotero.collections': 1, + }, + name: 'userId_1_sources.zotero.libraryType_1_sources.zotero.libraryId_1_sources.zotero.collections_1', + partialFilterExpression: { 'sources.zotero.itemKey': { $exists: true } }, + }, +] + +const migrate = async client => { + const { db } = client + await Helpers.addIndexesToCollection(db.libraryReferences, newIndexes) +} + +const rollback = async client => { + const { db } = client + await Helpers.dropIndexesFromCollection(db.libraryReferences, newIndexes) +} + +export default { + tags, + migrate, + rollback, +}