Skip to content

Commit 3abbdf2

Browse files
committed
fix: parallelize export sub-queries and use declaration year in PDF
- buildExportRows: run indicator G, CSE opinions and categories queries in parallel via Promise.all instead of sequentially - buildTransmittedPdfData: use declaration.year from DB instead of getCurrentYear() for the PDF year field
1 parent a864c70 commit 3abbdf2

2 files changed

Lines changed: 8 additions & 6 deletions

File tree

packages/app/src/modules/declarationPdf/buildTransmittedPdfData.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -43,7 +43,7 @@ export async function buildTransmittedPdfData(
4343
const [companyResults, declarationResults] = await Promise.all([
4444
db.select().from(companies).where(eq(companies.siren, siren)).limit(1),
4545
db
46-
.select({ id: declarations.id })
46+
.select({ id: declarations.id, year: declarations.year })
4747
.from(declarations)
4848
.where(and(eq(declarations.siren, siren), eq(declarations.year, year)))
4949
.limit(1),
@@ -90,7 +90,7 @@ export async function buildTransmittedPdfData(
9090
return {
9191
companyName: company.name,
9292
siren,
93-
year,
93+
year: declaration.year,
9494
generatedAt: formatLongDate(now),
9595
opinions,
9696
cseFiles,

packages/app/src/modules/export/buildExportRows.ts

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -65,11 +65,13 @@ export async function buildExportRows(
6565
);
6666

6767
const declarationIds = rows.map((r) => r.declarationId);
68-
const hasIndicatorG = await getDeclarationsWithIndicatorG(db, declarationIds);
69-
const cseMap = await getCseOpinionsByDeclaration(db, declarationIds);
70-
7168
const sirenYears = rows.map((r) => ({ siren: r.siren, year: r.year }));
72-
const categoriesMap = await getCategoriesByDeclaration(db, sirenYears);
69+
70+
const [hasIndicatorG, cseMap, categoriesMap] = await Promise.all([
71+
getDeclarationsWithIndicatorG(db, declarationIds),
72+
getCseOpinionsByDeclaration(db, declarationIds),
73+
getCategoriesByDeclaration(db, sirenYears),
74+
]);
7375

7476
return rows.map((row) => {
7577
const key = `${row.siren}-${row.year}`;

0 commit comments

Comments
 (0)