mirror of
https://github.com/outline/outline.git
synced 2026-06-13 11:25:03 +03:00
perf: Avoid redundant import lookup when presenting documents (#12529)
The FileOperation import association was fetched for every non-public document but only used when sourceMetadata is present. Move the lookup inside that branch to eliminate an N+1 query for documents that are not imports, benefiting every endpoint that presents documents. Co-authored-by: Claude Opus 4.8 <noreply@anthropic.com>
This commit is contained in:
@@ -103,8 +103,6 @@ async function presentDocument(
|
||||
}
|
||||
|
||||
if (!options.isPublic) {
|
||||
const source = document.import ?? (await document.$get("import"));
|
||||
|
||||
res.tasks = document.tasks;
|
||||
res.isCollectionDeleted = await document.isCollectionDeleted();
|
||||
res.collectionId = document.collectionId;
|
||||
@@ -118,15 +116,16 @@ async function presentDocument(
|
||||
if (options.includeCommentCount) {
|
||||
res.commentCount = await document.commentCount;
|
||||
}
|
||||
res.sourceMetadata = document.sourceMetadata
|
||||
? {
|
||||
importedAt: source?.createdAt ?? document.createdAt,
|
||||
importType: source?.format,
|
||||
createdByName: document.sourceMetadata.createdByName,
|
||||
fileName: document.sourceMetadata?.fileName,
|
||||
originalDocumentId: document.sourceMetadata?.originalDocumentId,
|
||||
}
|
||||
: undefined;
|
||||
if (document.sourceMetadata) {
|
||||
const source = document.import ?? (await document.$get("import"));
|
||||
res.sourceMetadata = {
|
||||
importedAt: source?.createdAt ?? document.createdAt,
|
||||
importType: source?.format,
|
||||
createdByName: document.sourceMetadata.createdByName,
|
||||
fileName: document.sourceMetadata?.fileName,
|
||||
originalDocumentId: document.sourceMetadata?.originalDocumentId,
|
||||
};
|
||||
}
|
||||
}
|
||||
|
||||
return res;
|
||||
|
||||
Reference in New Issue
Block a user