Skip to content

Commit

Permalink
Brochures' memory optimization
Browse files Browse the repository at this point in the history
Fix proposal
  • Loading branch information
gregory-buffard committed Nov 19, 2024
1 parent ab12c70 commit 2a5a44d
Showing 1 changed file with 4 additions and 3 deletions.
7 changes: 4 additions & 3 deletions web/actions/yachts.ts
Original file line number Diff line number Diff line change
Expand Up @@ -1171,10 +1171,10 @@ export const brochurize = async ({
headless: true,
args: ["--no-sandbox", "--disable-setuid-sandbox"],
}),
pdfBuffers: Uint8Array[] = [];
pdfBuffers: Uint8Array[] = [],
page = await browser.newPage();

for (const url of urls) {
const page = await browser.newPage();
await page.goto(url, { waitUntil: "networkidle0", timeout: 0 });

const pdfBuffer = await page.pdf({
Expand All @@ -1185,9 +1185,10 @@ export const brochurize = async ({
});

pdfBuffers.push(pdfBuffer);
await page.close();
await page.evaluate(() => window.gc && window.gc());
}

await page.close();
await browser.close();

const mergedPdf = await PDFDocument.create();
Expand Down

0 comments on commit 2a5a44d

Please sign in to comment.