From 32343fba24f684ff86b4cd9194a0cf42c801a4b3 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Fr=C3=A9d=C3=A9ric=20FRANCE?= Date: Tue, 3 Sep 2019 13:43:44 +0200 Subject: [PATCH] Optimize invoice situation doc with many many lines, it can be very very long to generate pdf --- htdocs/compta/facture/class/facture.class.php | 9 ++++++--- 1 file changed, 6 insertions(+), 3 deletions(-) diff --git a/htdocs/compta/facture/class/facture.class.php b/htdocs/compta/facture/class/facture.class.php index 33de9d47e18..1868c26c8fc 100644 --- a/htdocs/compta/facture/class/facture.class.php +++ b/htdocs/compta/facture/class/facture.class.php @@ -5168,13 +5168,16 @@ class FactureLigne extends CommonInvoiceLine public function get_prev_progress($invoiceid, $include_credit_note = true) { // phpcs:enable + global $invoicecache; if (is_null($this->fk_prev_id) || empty($this->fk_prev_id) || $this->fk_prev_id == "") { return 0; } else { // If invoice is not a situation invoice, this->fk_prev_id is used for something else - $tmpinvoice=new Facture($this->db); - $tmpinvoice->fetch($invoiceid); - if ($tmpinvoice->type != Facture::TYPE_SITUATION) return 0; + if (!isset($invoicecache[$invoiceid])) { + $invoicecache[$invoiceid]=new Facture($this->db); + $invoicecache[$invoiceid]->fetch($invoiceid); + } + if ($invoicecache[$invoiceid]->type != Facture::TYPE_SITUATION) return 0; $sql = 'SELECT situation_percent FROM ' . MAIN_DB_PREFIX . 'facturedet WHERE rowid=' . $this->fk_prev_id; $resql = $this->db->query($sql);