mirror of
https://github.com/opf/openproject.git
synced 2026-06-19 13:53:56 +00:00
599d94242d
We will be rendering the elements on the current page anyways, so it's unavoidable that we load them. By forcing us through to_a.size, we make sure that the elements are loaded first and then only count how many elements have been loaded. Since AR caches the result, the relation will not be loaded twice. Previously we had a useless SQL count query, which can be tremendously slower than the actual loading of elements. In the case of time entries for a larger database, the COUNT took ~1.5 seconds, when the loading of those same elements only took ~20ms. I don't hope that this ratio is generalizable to all collection API endpoints, but it's definitely a nice speed boost.