New index for querying items in a users synced collection

GitOrigin-RevId: aa81ca46cdd238a46a8002d1c991da787c1b9b0f
This commit is contained in:
Liam O'Brien
2026-09-17 11:29:59 +00:00
committed by Copybot
parent da808cf653
commit ae28403f9b
@@ -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,
}