#67837Extbase performs unnecessary count queries
Description
Quoting from https://jira.neos.io/browse/FLOW-326:
QueryResult::count() always execute a COUNT query, even if the results have been fetched or counted already.
This is especially an issue because we make use of this method a lot under the hood.
For example this (simplified but realistic) Fluid snippet:
<f:if condition="{products}">
<h1>{products -> f:count()} products:</h1>
<f:widget.paginate objects="{products}" as="paginatedProducts">
<ul>
<f:for each="{paginatedProducts}" as="product" iteration="iteration">
<li>{product.name}</li>
</f:for>
</ul>
</f:widget.paginate>
</f:if>
will execute the same SELECT COUNT(DISTINCT ... query four times.
And those counts can be very costly especially with complex queries or many rows in a INNODB table.