Taking to much time to load a view

Created on 31 August 2022, almost 2 years ago
Updated 27 February 2023, over 1 year ago

hi,
i've using this module to print overall values of all contents in view and it's working fine but it takes 3 to 4 minutes to load a view because i have 5000 contents in it,
here is my code.

/**
 * Implements hook_views_pre_render.
 * For Calculating Page Subtotal for Taxable and Invoice Fields.
 */
function pascatierp_invoice_views_pre_render(ViewExecutable $view) {
  if ($view->id() == 'view_all_invoices' || $view->id() == 'view_delivery_challan' || $view->id() == 'view_all_proforma') {
    $total = 0;
    $i = 0;
    $page_taxable_subtotal = $page_invoice_subtotal = 0;
    foreach ($view->result as $value) {
      $total_taxable = $value->_entity->get('field_taxable_value')->value;
      $total_invoice = $value->_entity->get('field_invoice_value')->value;
      $page_taxable_subtotal += $total_taxable;
      $page_invoice_subtotal += $total_invoice;
    }
    $view->totals['field_invoice_date'] = "PageSUM :- ____________\nTotalSUM :-\n____________ ";
    $view->totals['field_invoice_value'] =  $page_invoice_subtotal . " _____________________________ " . $view->totals['field_invoice_value'];
    $view->totals['field_taxable_value'] =  $page_taxable_subtotal . " _____________________________ " . $view->totals['field_taxable_value'];
  }
}

/**
 * Implements hook_views_pre_render.
 * For Calculating Overall for Taxable and Invoice Fields.
 */
function pascatierp_invoice_views_post_execute(ViewExecutable $view) {
  if ($view->id() == 'view_all_invoices' || $view->id() == 'view_delivery_challan' || $view->id() == 'view_all_proforma') {
    $total = [];
    $i = 0;
    $taxable_subtotal = $invoice_subtotal = 0;
    foreach ($view->result as $value) {
      $total_taxable = $value->_entity->get('field_taxable_value')->value;
      $total_invoice = $value->_entity->get('field_invoice_value')->value;
      $taxable_subtotal += $total_taxable;
      $invoice_subtotal += $total_invoice;
    }
    $view->totals['field_invoice_value'] =  isset($view->totals['field_invoice_value']) ? $invoice_subtotal . " _____________________________ " . $view->totals['field_invoice_value'] : $invoice_subtotal;
    $view->totals['field_taxable_value'] =  isset($view->totals['field_taxable_value']) ? $taxable_subtotal . " _____________________________ " . $view->totals['field_taxable_value'] : $taxable_subtotal;
  }
}

how do i fix it?

📌 Task
Status

Closed: cannot reproduce

Version

2.0

Component

Code

Created by

🇮🇳India Ali Rizvi

Live updates comments and jobs are added and updated live.
Sign in to follow issues

Comments & Activities

Not all content is available!

It's likely this issue predates Contrib.social: some issue and comment data are missing.

Production build 0.69.0 2024