perf: Remove N+1 query in documents.search (#12540)

This commit is contained in:
Tom Moor
2026-05-30 18:11:00 -04:00
committed by GitHub
parent d0ede882c6
commit 224230eaa0
+11 -10
View File
@@ -987,16 +987,17 @@ class Document extends ArchivableModel<
const findAllChildDocumentIds = async (
...parentDocumentId: string[]
): Promise<string[]> => {
const childDocuments = await (
this.constructor as typeof Document
).findAll({
attributes: ["id"],
where: {
parentDocumentId,
...where,
},
...options,
});
// Unscoped as this method only ever reads the id column
const childDocuments = await (this.constructor as typeof Document)
.unscoped()
.findAll({
attributes: ["id"],
where: {
parentDocumentId,
...where,
},
...options,
});
const childDocumentIds = childDocuments.map((doc) => doc.id);