[英]typo3 fluid f:for is extreamly slow
In my Typo3 extension I us a <f:for
to iterate trough a couple of items. 在我的Typo3扩展程序中,我们使用
<f:for
来迭代两个项目。 Exactly 184 Items. 恰好184个项目。
I generate a slider out of this. 我从中生成一个滑块。
Problem is that this iteration is extremly slow. 问题在于此迭代速度极慢。 Is there a way to fast it up.
有没有一种方法可以加快速度。 Backend is fast less than a sec.
后端速度不到一秒。 Only the frontend rendering needs to long time.
仅前端渲染需要很长时间。
My full frontend Code looks like this: 我完整的前端代码如下所示:
<f:if condition="{videos -> f:count()} > 4">
<f:then>
<f:for each="{videos}" as="video" iteration="i">
<f:if condition="{i.isFirst}">
<f:then>
<div class="item active">
</f:then>
<f:else>
<div class="item">
</f:else>
</f:if>
<div class="col-lg-3 thumbnailParent">
<f:link.action controller="FrontendVideo" action="show" arguments="{video : video}">
<f:render partial="Video/ShowThumbnail" arguments="{video : video, userAuthorization : userAuthorization}"/>
</f:link.action>
</div>
<!-- adding slider-class to one of all slides. condition: slide must have more than 4 videos for slide-effect -->
<f:if condition="{i.isLast}">
<f:then>
<script type="text/javascript">
addClassForSliding('{myCarouselID}');
function addClassForSliding(myCarouselID) {
$("#myCarousel"+myCarouselID).addClass("isCarousel");
if(!$("div.videoSlide").find("div").hasClass("thisIsTheOnlySliderWhichSlides")){
$("#myCarousel"+myCarouselID).addClass("thisIsTheOnlySliderWhichSlides");
}
}
</script>
</f:then>
<f:else></f:else>
</f:if>
</div>
</f:for>
</f:then>
<f:else>
<f:for each="{videos}" as="video" iteration="i">
<div class="item active">
<div class="col-lg-3">
<f:link.action controller="FrontendVideo" action="show" arguments="{video : video}">
<f:render partial="Video/ShowThumbnail" arguments="{video : video, userAuthorization : userAuthorization}"/>
</f:link.action>
</div>
</div>
</f:for>
</f:else>
</f:if>
<f:else></f:else>
. <f:else></f:else>
类的空节点。 iteration
variable whenever possible. iteration
变量。 It adds additional processing and variable assignment to each iteration. active
CSS class, thus avoiding 1) opening and closing tags incorrectly like you do, and 2) avoid another condition that only is true a single time, like the other one. active
CSS类,从而避免1)像您一样错误地打开和关闭标签,以及2)避免仅一次有效的另一种情况,例如另一种情况。 <script>
in Fluid unless you have an extremely good reason. <script>
。 Whenever possible, load scripts externally and store whichever values the script needs, in for example data-
properties. data-
属性。 Faster parsing, faster loop. f:render
calls. f:render
调用中需要完成的处理越多。 Do not profile in development context! Avoiding iteration
and your conditions, and moving the last block outside the loop, should remove a good 80% of the cost (not counting what happens in your partial you render - it could be absolutely horrible in performance and we'd never know since you didn't paste that one). 避免
iteration
和您的条件,并将最后一个块移到循环外,应该可以节省80%的成本(不计算您渲染的部分中发生的事情-这在性能上绝对是可怕的,我们永远不会知道,因为您没有粘贴那个)。
Finally, when selecting whether to render a partial or a section there are a couple of things to consider. 最后,在选择是渲染部分片段还是部分片段时,需要考虑几件事。 Most of these completely depend on your use case (as in: how do you need your templates to be structured - does it make more sense with a partial you can overlay than a section you cannot?) but it is possible to say something general about performance:
其中大多数完全取决于您的用例(例如:您如何需要对模板进行结构化-与您无法覆盖的部分相比,可以覆盖的部分是否更有意义?),但是可以说一些笼统的内容性能:
You always need to choose the right tool for the task - that's one of the things our job is as developers - so these points are pretty generic. 您始终需要为任务选择正确的工具-这是我们作为开发人员要做的事情之一-因此,这些要点很通用。 Some uses cases simply have no difference in performance between sections and partials, some don't suffer noticeably from using
iteration
; 有些用例在部分和部分之间的性能完全没有差异,而有些则不会因为使用
iteration
而明显受苦; it all depends on your setup requirements and the data you are rendering. 这完全取决于您的设置要求和要呈现的数据。 Profiling your templates certainly helps finding the right solution so I highly recommend doing that.
对模板进行性能分析无疑有助于找到正确的解决方案,因此我强烈建议您这样做。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.