Page 1 of 1

unnecessary queries when no results

Posted: Sat Mar 16, 2019 12:30 pm
by letxobnav
Not sure if this was addressed before...

in 3.0.2.0 it is still the practice for product searches to:

Code: Select all

			$product_total = $this->model_catalog_product->getTotalProducts($filter_data);
			$results = $this->model_catalog_product->getProducts($filter_data);
This means even if the $product_total equals zero we do the second query anyway.

I kindly suggest:

Code: Select all

			$product_total = $this->model_catalog_product->getTotalProducts($filter_data);
			if ($product_total > 0) {
				$results = $this->model_catalog_product->getProducts($filter_data);
			} else {
				$results = false;
			}

Re: unnecessary queries when no results

Posted: Sat Mar 16, 2019 12:49 pm
by IP_CAM
Well, a much more comfortable way, to avoid unnecessary queries,
would be, not to use any, if not required, i.E., by use of the famous
Cache Category Counting Extension: ;)
viewtopic.php?f=190&t=210525&p=749342#p749234
Ernie

Re: unnecessary queries when no results

Posted: Sat Mar 16, 2019 1:15 pm
by letxobnav
true, but I am always careful with caching as my filters are very dynamic, not showing when empty for instance, same for filter groups.
Not against queries, just the obvious unnecessary ones.

I think I have that DB cache extension but it seems it gives me error 500's over time and they disappear when I delete the cache file. Have not traced the cause yet though.

will check the other.