The latest version of tt_news (3.0.0 development) has been said to improve performance. However, it still leaves a lot to be desired. Indexing tables can speed up some queries, but the reason why tt_news is so slow is the number of queries it generates, especially in LIST view. Stepping through the extension with the debugger shows how big the problem really is. There are plenty of tips about optimizing tt_news cache in the tt_news news list, but they bypass the main problem – the fact that tt_news is s-l-o-w. Below you will find the way that I have used to speed up significantly the generation of the LIST. It requires modifying tt_news code, and requires some understanding of the structure of the 4,000+ line PHP file. It can be used on any recent version, not just the latest, and requires customization in each case. All changes take place in /pi/class.tx_ttnews.php
The one function in the current development version of tt_news is isRenderField, which (although undocumented) checks if the field is supposed to be displayed. Unfortunately, this function does not work as desired – it requires TypoScript setup, that, again is undocumented in this development version.
I wrote these functions as a replacement. What they do is parse the template part for markers, and later in the functions check if the markers are present. If the marker is not used in the template, why spend time to query the database and run lines of code?
function isRenderMarker($marker) {
if (in_array($marker, $this->renderMarkers))
return true;
return false;
}
function getMarkers($template)
{
preg_match_all('/###(.+)###/Us', $template, $matches);
return $matches[0];
}
When loading the template, it has to be parsed for markers. In tt_news 3.0.0, it is done here:
$t['total'] = $this->getNewsSubpart($this->templateCode, $this->spMarker('###' . $templateName . '###'));
$t['item'] = $this->getLayouts($t['total'], $this->alternatingLayouts, 'NEWS');
// Parse out markers in the templates to prevent unnecessary queries and code from executing
$markers = $this->getMarkers($t['total']);
foreach($t['item'] as $item)
$markers = array_merge($markers, $this->getMarkers($item));
$this->renderMarkers = array_unique($markers);
Now, just go through the rest of the code (specifically getItemMarkerArray), and wrap any part with the if statement:
if($this->isRenderMarker('###MARKER###'))
{
// render the field
}
For example:
// get image markers
$markerArray['###NEWS_IMAGE###'] = '';
if ($this->isRenderField('image') && $this->isRenderMarker('###NEWS_IMAGE###')) {
$markerArray = $this->getImageMarkers($markerArray, $row, $lConf, $textRenderObj);
}
Make sure to go through any function that extend tt_news (comments, tt_ratings, etc) by using the extra marker hook, and add the code there, as these functions are executed for each item in the list and might waste a lot of time and resources if their output is never displayed. Example:
function extraItemMarkerProcessor($markerArray, $row, $lConf, &$pObj) {
if($pObj->isRenderMarker('###TX_COMMENTS_COUNT###'))
{
// Stuff
}
}
Results? LIST view generation time decreased from 20-30 seconds to 0.7-1.4 seconds. I hope this was the intention of the isRenderField function, and will make it to the final release of tt_news 3.0
Patch for testing:tt_news_performance_patch