mirror of
https://github.com/documenso/documenso.git
synced 2026-07-25 17:35:05 +10:00
perf: parallelize independent async operations in createEnvelope (#2618)
This commit is contained in:
@@ -265,18 +265,6 @@ export const createEnvelope = async ({
|
|||||||
// for uploads from the frontend
|
// for uploads from the frontend
|
||||||
const timezoneToUse = meta?.timezone || settings.documentTimezone || userTimezone;
|
const timezoneToUse = meta?.timezone || settings.documentTimezone || userTimezone;
|
||||||
|
|
||||||
const documentMeta = await prisma.documentMeta.create({
|
|
||||||
data: extractDerivedDocumentMeta(settings, {
|
|
||||||
...meta,
|
|
||||||
timezone: timezoneToUse,
|
|
||||||
}),
|
|
||||||
});
|
|
||||||
|
|
||||||
const secondaryId =
|
|
||||||
type === EnvelopeType.DOCUMENT
|
|
||||||
? await incrementDocumentId().then((v) => v.formattedDocumentId)
|
|
||||||
: await incrementTemplateId().then((v) => v.formattedTemplateId);
|
|
||||||
|
|
||||||
const getValidatedDelegatedOwner = async () => {
|
const getValidatedDelegatedOwner = async () => {
|
||||||
if (
|
if (
|
||||||
!settings.delegateDocumentOwnership ||
|
!settings.delegateDocumentOwnership ||
|
||||||
@@ -311,7 +299,18 @@ export const createEnvelope = async ({
|
|||||||
return delegatedOwner;
|
return delegatedOwner;
|
||||||
};
|
};
|
||||||
|
|
||||||
const delegatedOwner = await getValidatedDelegatedOwner();
|
const [documentMeta, secondaryId, delegatedOwner] = await Promise.all([
|
||||||
|
prisma.documentMeta.create({
|
||||||
|
data: extractDerivedDocumentMeta(settings, {
|
||||||
|
...meta,
|
||||||
|
timezone: timezoneToUse,
|
||||||
|
}),
|
||||||
|
}),
|
||||||
|
type === EnvelopeType.DOCUMENT
|
||||||
|
? incrementDocumentId().then((v) => v.formattedDocumentId)
|
||||||
|
: incrementTemplateId().then((v) => v.formattedTemplateId),
|
||||||
|
getValidatedDelegatedOwner(),
|
||||||
|
]);
|
||||||
const envelopeOwnerId = delegatedOwner?.id ?? userId;
|
const envelopeOwnerId = delegatedOwner?.id ?? userId;
|
||||||
|
|
||||||
const createdEnvelope = await prisma.$transaction(async (tx) => {
|
const createdEnvelope = await prisma.$transaction(async (tx) => {
|
||||||
|
|||||||
Reference in New Issue
Block a user