Permalink
Browse files

The product cache caused an endless loop when no results were found.

  • Loading branch information...
1 parent 794da90 commit bc82710d68479b98317c78eac79736230e7f1344 @psi-4ward committed Mar 20, 2012
Showing with 30 additions and 31 deletions.
  1. +2 −0 system/modules/isotope/CHANGELOG.md
  2. +28 −31 system/modules/isotope/ModuleIsotopeProductList.php
@@ -10,6 +10,8 @@ Version 1.3.0 stable (2012-??-??)
### Fixed
- Do not initialize a cart when running the Contao cron job
+- Force type comparison when checking for BE_/FE_USER_LOGGED_IN (fixes #2976)
+- The product cache caused an endless loop when no results were found
Version 1.3.rc2 (2012-03-19)
@@ -126,7 +126,7 @@ protected function compile()
// Cache found
if ($objCache->numRows)
{
- $arrCacheIds = explode(',', $objCache->products);
+ $arrCacheIds = $objCache->products == '' ? array() : explode(',', $objCache->products);
// Use the cache if keywords match. Otherwise we will use the product IDs as a "limit" for findProducts()
if ($objCache->keywords == $this->Input->get('keywords'))
@@ -177,42 +177,39 @@ protected function compile()
// Load products
$arrProducts = $this->findProducts($arrCacheIds);
- if (!empty($arrProducts))
+ // Decide if we should show the "caching products" message the next time
+ $end = microtime(true) - $start;
+ $this->blnCacheProducts = $end > 1 ? true : false;
+
+ if ($blnCacheMessage != $this->blnCacheProducts)
{
- // Decide if we should show the "caching products" message the next time
- $end = microtime(true) - $start;
- $this->blnCacheProducts = $end > 1 ? true : false;
+ $arrCacheMessage = $this->iso_productcache;
+ $arrCacheMessage[$objPage->id][(int) $this->Input->get('isorc')] = $this->blnCacheProducts;
+ $this->Database->prepare("UPDATE tl_module SET iso_productcache=? WHERE id=?")->execute(serialize($arrCacheMessage), $this->id);
+ }
- if ($blnCacheMessage != $this->blnCacheProducts)
- {
- $arrCacheMessage = $this->iso_productcache;
- $arrCacheMessage[$objPage->id][(int) $this->Input->get('isorc')] = $this->blnCacheProducts;
- $this->Database->prepare("UPDATE tl_module SET iso_productcache=? WHERE id=?")->execute(serialize($arrCacheMessage), $this->id);
- }
+ // Do not write cache if table is locked. That's the case if another process is already writing cache
+ if ($this->Database->query("SHOW OPEN TABLES FROM `{$GLOBALS['TL_CONFIG']['dbDatabase']}` LIKE 'tl_iso_productcache'")->In_use == 0)
+ {
+ $this->Database->lockTables(array('tl_iso_productcache'=>'WRITE', 'tl_iso_products'=>'READ'));
+ $arrIds = array();
- // Do not write cache if table is locked. That's the case if another process is already writing cache
- if ($this->Database->query("SHOW OPEN TABLES FROM `{$GLOBALS['TL_CONFIG']['dbDatabase']}` LIKE 'tl_iso_productcache'")->In_use == 0)
+ foreach ($arrProducts as $objProduct)
{
- $this->Database->lockTables(array('tl_iso_productcache'=>'WRITE', 'tl_iso_products'=>'READ'));
- $arrIds = array();
-
- foreach ($arrProducts as $objProduct)
- {
- $arrIds[] = $objProduct->id;
- }
-
- $intExpires = (int) $this->Database->execute("SELECT MIN(start) AS expires FROM tl_iso_products WHERE start>$time")
- ->expires;
+ $arrIds[] = $objProduct->id;
+ }
+
+ $intExpires = (int) $this->Database->execute("SELECT MIN(start) AS expires FROM tl_iso_products WHERE start>$time")
+ ->expires;
- // Also delete all expired caches if we run a delete anyway
- $this->Database->prepare("DELETE FROM tl_iso_productcache WHERE (page_id=? AND module_id=? AND requestcache_id=? AND keywords=?) OR (expires>0 AND expires<$time)")
- ->executeUncached($objPage->id, $this->id, (int)$this->Input->get('isorc'), (string)$this->Input->get('keywords'));
+ // Also delete all expired caches if we run a delete anyway
+ $this->Database->prepare("DELETE FROM tl_iso_productcache WHERE (page_id=? AND module_id=? AND requestcache_id=? AND keywords=?) OR (expires>0 AND expires<$time)")
+ ->executeUncached($objPage->id, $this->id, (int)$this->Input->get('isorc'), (string)$this->Input->get('keywords'));
- $this->Database->prepare("INSERT INTO tl_iso_productcache (page_id,module_id,requestcache_id,keywords,products,expires) VALUES (?,?,?,?,?,?)")
- ->executeUncached($objPage->id, $this->id, (int)$this->Input->get('isorc'), (string)$this->Input->get('keywords'), implode(',', $arrIds), $intExpires);
+ $this->Database->prepare("INSERT INTO tl_iso_productcache (page_id,module_id,requestcache_id,keywords,products,expires) VALUES (?,?,?,?,?,?)")
+ ->executeUncached($objPage->id, $this->id, (int)$this->Input->get('isorc'), (string)$this->Input->get('keywords'), implode(',', $arrIds), $intExpires);
- $this->Database->unlockTables();
- }
+ $this->Database->unlockTables();
}
}
else
@@ -288,7 +285,7 @@ protected function findProducts($arrCacheIds=null)
protected function generatePagination($total)
{
// Add pagination
- if ($this->perPage > 0)
+ if ($this->perPage > 0 && $total > 0)
{
$page = $this->Input->get('page') ? $this->Input->get('page') : 1;

0 comments on commit bc82710

Please sign in to comment.