mirror of
https://github.com/outline/outline.git
synced 2026-06-13 11:25:03 +03:00
perf: Remove N+1 query in documents.search (#12540)
This commit is contained in:
+11
-10
@@ -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);
|
||||
|
||||
|
||||
Reference in New Issue
Block a user