简体   繁体   中英

Opencart 3 getProduct method causes slow page loading

My Opencart 3.0 is running very slow. In the.network tab in the chrome browser inspector, it records 23.02 seconds for the category page to load.

When I try to debug it, I could see that the slow loading happens here

catalog/model/catalog/product.php - public function getProduct($product_id)

Inside this method, when I comment out this line in the returned array - 'product_id' => $query->row['product_id'] , the loading speed comes to 7s.

The method getProduct($product_id) is called in this method getProducts($data = array()) . The part where the method is called looks like below.

$query = $this->db->query($sql);
foreach ($query->rows as $result) {
   $product_data[$result['product_id']] = $this->getProduct($result['product_id']);
}

When I comment out this line

//$product_data[$result['product_id']] = $this->getProduct($result['product_id']);

The loading speed goes to 3.5s.

What I could not figure out is why this part of the code takes time to return - 'product_id' => $query->row['product_id']

I will appreciate your help.

It look like your issues comes from getProduct() and getProducts() methods in the catalog/model/catalog/product.ph p file. Especially this row:

'product_id' => $query->row['product_id']

So you could check your DB performance, how much time is taking to complete this query.

  1. If it takes too much time and your columns are not indexed, you could index them.
  1. You could also try to limit the number of rows being retrieved in the query by using a LIMIT clause or a WHERE clause.

  2. You could use Opencart cache system, to reduce time.

On first sign it looks more like DB related problem, instead of code problem.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM