Index: t3lib/cache/backend/class.t3lib_cache_backend_dbbackend.php =================================================================== --- t3lib/cache/backend/class.t3lib_cache_backend_dbbackend.php (revision 6604) +++ t3lib/cache/backend/class.t3lib_cache_backend_dbbackend.php (working copy) @@ -289,20 +299,13 @@ * @return void */ public function flushByTag($tag) { - $GLOBALS['TYPO3_DB']->exec_DELETEquery( - $this->cacheTable, - 'identifier IN (' . - $GLOBALS['TYPO3_DB']->SELECTsubquery( - 'identifier', - $this->tagsTable, - $this->getQueryForTag($tag) - ) . - ')' - ); + $tagsTableWhereClause = $this->getQueryForTag($tag); + $this->deleteCacheTableRowsByTagsTableWhereClause($tagsTableWhereClause); + $GLOBALS['TYPO3_DB']->exec_DELETEquery( $this->tagsTable, - $this->getQueryForTag($tag) + $this->getQueryForTag($tagsTableWhereClause) ); } @@ -319,20 +322,13 @@ $listQueryConditions[$tag] = $this->getQueryForTag($tag); } - $GLOBALS['TYPO3_DB']->exec_DELETEquery( - $this->cacheTable, - 'identifier IN (' . - $GLOBALS['TYPO3_DB']->SELECTsubquery( - 'identifier', - $this->tagsTable, - implode(' OR ', $listQueryConditions) - ) . - ')' - ); + $tagsTableWhereClause = implode(' OR ', $listQueryConditions); + $this->deleteCacheTableRowsByTagsTableWhereClause($tagsTableWhereClause); + $GLOBALS['TYPO3_DB']->exec_DELETEquery( $this->tagsTable, - implode(' OR ', $listQueryConditions) + $tagsTableWhereClause ); } } @@ -344,17 +340,25 @@ * @author Ingo Renner */ public function collectGarbage() { - $GLOBALS['TYPO3_DB']->exec_DELETEquery( - $this->tagsTable, - 'identifier IN (' . - $GLOBALS['TYPO3_DB']->SELECTsubquery( - 'identifier', - $this->cacheTable, - 'crdate + lifetime < ' . $GLOBALS['EXEC_TIME'] . ' AND lifetime > 0' - ) . - ')' + $tagsEntryIdentifierRowsRessource = $GLOBALS['TYPO3_DB']->exec_SELECTquery( + 'identifier', + $this->cacheTable, + 'crdate + lifetime < ' . $GLOBALS['EXEC_TIME'] . ' AND lifetime > 0' ); + $tagsEntryIdentifiers = array(); + while ($tagsEntryIdentifierRow = $GLOBALS['TYPO3_DB']->sql_fetch_assoc($tagsEntryIdentifierRowsRessource)) { + $tagsEntryIdentifiers[] = $tagsEntryIdentifierRow['identifier']; + } + $GLOBALS['TYPO3_DB']->sql_free_result($cacheEntryIdentifierRowsRessource); + + if (count($tagsEntryIdentifiers)) { + $GLOBALS['TYPO3_DB']->exec_DELETEquery( + $this->tagsTable, + 'identifier IN (\'' .implode('\', \'', $tagsEntryIdentifiers) . '\')' + ); + } + $GLOBALS['TYPO3_DB']->exec_DELETEquery( $this->cacheTable, 'crdate + lifetime < ' . $GLOBALS['EXEC_TIME'] . ' AND lifetime > 0' @@ -457,6 +461,33 @@ return $query; } + + /** + * Deletes rows in cache table found by where clause on tags table + * + * @param string The where clause for the tags table + * @return void + */ + protected function deleteCacheTableRowsByTagsTableWhereClause($tagsTableWhereClause) { + $cacheEntryIdentifierRowsRessource = $GLOBALS['TYPO3_DB']->exec_SELECTquery( + 'DISTINCT identifier', + $this->tagsTable, + $tagsTableWhereClause + ); + + $cacheEntryIdentifiers = array(); + while ($cacheEntryIdentifierRow = $GLOBALS['TYPO3_DB']->sql_fetch_assoc($cacheEntryIdentifierRowsRessource)) { + $cacheEntryIdentifiers[] = $cacheEntryIdentifierRow['identifier']; + } + $GLOBALS['TYPO3_DB']->sql_free_result($cacheEntryIdentifierRowsRessource); + + if (count($cacheEntryIdentifiers)) { + $GLOBALS['TYPO3_DB']->exec_DELETEquery( + $this->cacheTable, + 'identifier IN (\'' .implode('\', \'', $cacheEntryIdentifiers) . '\')' + ); + } + } }