The problem itself is solved, but the question is still open cause I want to test the tipps from Krystian. See Edit 3 at the bottom of this question.
I have a TYPO3 project that is very slow. So I did some tests and found some problems.
I tested the startpage, the startpage containers 2 news list (total 9 articles) (tx_news version 2.3.0 - not the newest one). It contains the menu (created with fluid v:page.menu), the footer (also created with v:page.menu), a right column (mainly image content elements, gathered from another page with typoscript) and a news-taglist (created with typoscript). The news-taglist is used twice - once in the menu and once in the right column.
First the performance overview:
No Menu/No Footer (without taglist), No News, No Labellist
0.65s
With menu and footer (without taglist)
0.95s
With menu and footer (with taglist)
2.3s
With menu and footer (with taglist) and Taglist in right column
3s
With all
4.2s
A big point is the taglist (right now there is a total of 1303 tags). here is the Typoscript that generate the taglist:
plugin.tx_mytemplate {
newsTags = CONTENT
newsTags {
table = tx_news_domain_model_tag
select {
pidInList = 1,589
hidden = 0
deleted = 0
orderBy = title
}
orderBy = title
renderObj = COA
renderObj {
1 = LOAD_REGISTER
1 {
Counter.cObject = TEXT
Counter.cObject.data = register:Counter
Counter.cObject.wrap = |+1
Counter.prioriCalc = intval
}
2 = TEXT
2.insertData = 1
2 = TEXT
2.insertData = 1
2.field = title
2.typolink {
# link to page
parameter = 588
# the current tag
additionalParams = &tx_news_pi1[overwriteDemand][tags]={field:uid}
additionalParams.insertData = 1
}
2.wrap = <li data-test="{field:uid}" data-index="{register:Counter}">|</li>
}
wrap = <ul>|</ul>
}
}
I use this once in the menu and once in a content element with:
<f:cObject typoscriptObjectPath="plugin.tx_mytemplate.newsTags" />
What I don't understand is, for my understanding there should not be a big difference in using it once or twice (or even more), cause after the first use the typoscript-object should be created and there is no need to create it a second time. Am I missing something here?
This is the SQL:
SELECT * FROM tx_news_domain_model_tag WHERE tx_news_domain_model_tag.pid IN (1,589) AND tx_news_domain_model_tag.deleted=0 AND tx_news_domain_model_tag.hidden=0 ORDER BY title;
It needs 0.004s to execute this query. So the other point I don't understand is, why is it so expensive to create this typoscript-object? Is it the typolink that is used to create all 1303 Links? (I used realURL)
Also, this taglist does not change often, is it somehow possible to full cache it? And for example only create a new taglist when Flush general caches (or frontend cahches) is executed?
Any other ideas? ( I know I could load the taglist via ajax after the page is loaded, but that is just the last work around and maybe there are better solutions)
Edit: I tested the taglist without the typolink and its around 1s faster. That means to create a typolink for 1303 Link costs around 1s.
Edit 2: I found a hidden config.no_cache = 1
And testing right now if everything works when cache is enabled. But anyway I am interessted why typolink is so expensive.
.
Edit 3: I test Krystians answer:
Cache the Typoscript Object with stdWrap.cache.key = someHash
plugin.tx_mytemplate {
newsTags = CONTENT
newsTags {
table = tx_news_domain_model_tag
select {
pidInList = 1,589
hidden = 0
deleted = 0
orderBy = title
}
orderBy = title
renderObj = COA
renderObj {
1 = LOAD_REGISTER
1 {
Counter.cObject = TEXT
Counter.cObject.data = register:Counter
Counter.cObject.wrap = |+1
Counter.prioriCalc = intval
}
2 = TEXT
2.insertData = 1
2 = TEXT
2.insertData = 1
2.field = title
2.typolink {
# link to page
parameter = 588
# the current tag
additionalParams = &tx_news_pi1[overwriteDemand][tags]={field:uid}
additionalParams.insertData = 1
}
2.wrap = <li data-test="{field:uid}" data-index="{register:Counter}">|</li>
}
wrap = <ul>|</ul>
stdWrap.cache.key = mytaglist
stdWrap.cache.lifetime = unlimited
}
}
I can't see any changes in loading time. is there a way to check if this object really gets cached? Did I something wrong?
Using VHS to cache the content with v:render.cache
I replaced
<f:cObject typoscriptObjectPath="plugin.tx_mytemplate.newsTags" />
with
<v:render.cache content="<f:cObject typoscriptObjectPath='plugin.tx_mytemplate.newsTags' />" identity="test1234" />
It seems to work, cause the first call needs longer. But then the next call is "normal" (as I would not use the v.render.cache) until I take the content part out and just use the identify:
<v:render.cache content="test" identity="test1234" />
This is faster and still displays the taglist. So it works so far, that the cached version behind test1234
is used. But it also seems that he render the f:cObject typoscript object
in the content part every time. What am I missing here?
Even stranger is, when I use the code with content="test"
and flush frontend caches
and flush general caches
the taglist is still displayed (and not "test"). The docu says: The cache behind this ViewHelper is the Extbase object cache, which is cleared when you clear the page content cache.
. What exactly is the page content cache? Not one of the two flush frontend caches
or flush general caches
?
Edit 4: With cache enabled I found a problem with the news plugin. I use realURL for the newsplugin:
'category' => array(
array(
'GETvar' => 'tx_news_pi1[overwriteDemand][categories]',
'lookUpTable' => array(
'table' => 'tx_news_domain_model_category',
'id_field' => 'uid',
'alias_field' => 'CONCAT(title, "-", uid)',
'addWhereClause' => ' AND NOT deleted',
'useUniqueCache' => 1,
'useUniqueCache_conf' => array(
'strtolower' => 1,
'spaceCharacter' => '-'
)
)
)
),
'tag' => array(
array(
'GETvar' => 'tx_news_pi1[overwriteDemand][tags]',
'lookUpTable' => array(
'table' => 'tx_news_domain_model_tag',
'id_field' => 'uid',
'alias_field' => 'CONCAT(title, "-", uid)',
'addWhereClause' => ' AND NOT deleted',
'useUniqueCache' => 1,
'useUniqueCache_conf' => array(
'strtolower' => 1,
'spaceCharacter' => '-'
)
)
)
),
Calling a category link works without problem, but when I call a tag link then I see only the news from the first hit (changing the tag does not affect anything, it still shows the news filtered by the first tag). So it seems something went wrong there with the cache, but I can not figure out what. For me categories and tag looks pretty much the same, the only difference is another parameter, but realURL should handle that.
The first thing you can do is to cache all elements that are common for all pages. Good candidates for that are header and footer elements and in your case maybe the tag list. If you have header done with typoscript then you can use "cache" property of stdWrap.
Read the docs here: http://docs.typo3.org/typo3cms/TyposcriptReference/Functions/Cache/Index.html
If you use this construction then this element is rendered on first page hit. Then for all next pages when TYPO3 needs to render this element it uses value from cache.
If you think that you can not use it for menu becase you have states like "active"/"current" then you are wrong. You can set the staes using Javascript. Here the example.
If you use Fluid then you can also use such caching of common element. Install ext: vhs and then use this ViewHelper https://fluidtypo3.org/viewhelpers/vhs/1.1.0/Render/CacheViewHelper.html