Improve performance of previews and prevent double renders

This commit is contained in:
David Bomba
2026-05-04 15:07:08 +10:00
parent 55e80c2ac1
commit 8bd285af19
3 changed files with 43 additions and 5 deletions

View File

@@ -195,7 +195,7 @@ class PreviewController extends BaseController
$requestDesign = $request->design['design'];
$ps->boot();
$ps->bootForPreviewDesign($requestDesign);
if (isset($requestDesign['blocks'])) {
$ps->setJsonDesignHtml(

View File

@@ -82,6 +82,37 @@ class PdfService
return $this;
}
/**
* Initialize the PDF context for design preview rendering without building
* the currently-saved design first. The caller will render the request
* design after this method prepares config, settings, locale variables, and
* the designer/builder shells.
*/
public function bootForPreviewDesign(array $previewDesign): self
{
$this->start_time = microtime(true);
$this->config = (new PdfConfiguration($this))->init();
$this->applyJsonDesignSettingsOverrides($previewDesign);
$htmlEngine = ($this->invitation instanceof \App\Models\PurchaseOrderInvitation)
? new VendorHtmlEngine($this->invitation)
: new HtmlEngine($this->invitation);
$htmlEngine->setSettings($this->config->settings);
$this->html_variables = $htmlEngine->generateLabelsAndValues();
$this->designer = new PdfDesigner($this);
$this->designer->template = '';
$this->builder = new PdfBuilder($this);
$this->builder->document = new \DOMDocument();
$this->builder->document->loadHTML('<!DOCTYPE html><html><body></body></html>');
return $this;
}
/**
* Resolves the PDF generation type and
* attempts to generate a PDF from the HTML
@@ -199,13 +230,19 @@ class PdfService
*
* No-op for non-JSON designs and for JSON designs with no documentSettings.
*/
private function applyJsonDesignSettingsOverrides(): void
private function applyJsonDesignSettingsOverrides(?array $designData = null): void
{
if (!$this->isJsonDesign()) {
return;
if ($designData === null) {
if (!$this->isJsonDesign()) {
return;
}
$designData = $this->config->decodedDesign();
}
$designData = $this->config->decodedDesign();
if ($designData === null || !isset($designData['blocks'])) {
return;
}
$resolver = new DocumentSettingsResolver($designData, $this->config->settings);

View File

@@ -6029,6 +6029,7 @@ $lang = array(
'label_value_gap' => 'Gap between label and value.',
'row_spacing' => 'How much vertical space sits between each row.',
'value_min_width' => 'Minimum width for values.',
'fix_overlaps' => 'Fix Overlaps',
);