mirror of
https://github.com/GitbookIO/gitbook.git
synced 2026-09-16 15:45:13 +00:00
Parallelize and remove useless Promise.all (#2581)
This commit is contained in:
@@ -874,13 +874,11 @@ export async function getSpaceContentData(
|
||||
spaceId: pointer.spaceId,
|
||||
revisionId: changeRequest?.revision ?? pointer.revisionId ?? space.revision,
|
||||
};
|
||||
const [pages] = await Promise.all([
|
||||
getRevisionPages(space.id, contentTarget.revisionId, {
|
||||
// We only care about the Git metadata when the Git sync is enabled
|
||||
// otherwise we can optimize performance by not fetching it
|
||||
metadata: !!space.gitSync,
|
||||
}),
|
||||
]);
|
||||
const pages = await getRevisionPages(space.id, contentTarget.revisionId, {
|
||||
// We only care about the Git metadata when the Git sync is enabled
|
||||
// otherwise we can optimize performance by not fetching it
|
||||
metadata: !!space.gitSync,
|
||||
});
|
||||
|
||||
return {
|
||||
space,
|
||||
|
||||
@@ -161,28 +161,31 @@ export async function middleware(request: NextRequest) {
|
||||
userAgent: userAgent(),
|
||||
}),
|
||||
async () => {
|
||||
// Start fetching everything as soon as possible, but do not block the middleware on it
|
||||
// the cache will handle concurrent calls
|
||||
await waitUntil(
|
||||
getSpaceContentData(
|
||||
{
|
||||
spaceId: resolved.space,
|
||||
changeRequestId: resolved.changeRequest,
|
||||
revisionId: resolved.revision,
|
||||
},
|
||||
'site' in resolved ? resolved.shareKey : undefined,
|
||||
const [siteData] = await Promise.all([
|
||||
'site' in resolved
|
||||
? getSiteData({
|
||||
organizationId: resolved.organization,
|
||||
siteId: resolved.site,
|
||||
siteSectionId: resolved.siteSection,
|
||||
siteSpaceId: resolved.siteSpace,
|
||||
siteShareKey: resolved.shareKey,
|
||||
})
|
||||
: null,
|
||||
// Start fetching everything as soon as possible, but do not block the middleware on it
|
||||
// the cache will handle concurrent calls
|
||||
waitUntil(
|
||||
getSpaceContentData(
|
||||
{
|
||||
spaceId: resolved.space,
|
||||
changeRequestId: resolved.changeRequest,
|
||||
revisionId: resolved.revision,
|
||||
},
|
||||
'site' in resolved ? resolved.shareKey : undefined,
|
||||
),
|
||||
),
|
||||
);
|
||||
]);
|
||||
|
||||
const { scripts } = await ('site' in resolved
|
||||
? getSiteData({
|
||||
organizationId: resolved.organization,
|
||||
siteId: resolved.site,
|
||||
siteSectionId: resolved.siteSection,
|
||||
siteSpaceId: resolved.siteSpace,
|
||||
siteShareKey: resolved.shareKey,
|
||||
})
|
||||
: { scripts: [] });
|
||||
const scripts = siteData?.scripts ?? [];
|
||||
return getContentSecurityPolicy(scripts, nonce);
|
||||
},
|
||||
);
|
||||
|
||||
Reference in New Issue
Block a user