title: TYPO3: Performance issue with pagination
body: <p>I am currently building some kind of video channel based on an extension I created. It consists of videos and playlist that contains videos (obviously).
  I have to create a page which contains a list of videos AND playlist by category. You also can sort those items by date. Finally, the page is paginated with an infinite scrolling that should load items 21 by 21.
  To do so, I created on both Video and Playlist repositories a "findByCategory" function which is really simple :</p>
  
  <pre><code>$query = $this-&gt;createQuery();
      return $query-&gt;matching($query-&gt;equals('categorie.uid',$categoryUid))-&gt;execute()-&gt;toArray();
  </code></pre>
  
  <p>Once I requested the items I need, I merge them in one array and do my sorting stuff. Here is my controller show action :</p>
  
  <pre><code>    if ($this-&gt;request-&gt;hasArgument('sort'))
          $sort = $this-&gt;request-&gt;getArgument('sort');
      else
          $sort = 'antechrono';
      //Get videos in repositories
      $videos = $this-&gt;videoRepository-&gt;findByCategorie($categorie-&gt;getUid());
      $playlists = $this-&gt;playlistRepository-&gt;findByCategorie($categorie-&gt;getUid());
      //Merging arrays then sort it
      if ($videos &amp;&amp; $playlists)
          $result = array_merge($videos, $playlists);
      else if ($videos)
          $result = $videos;
      else if ($playlists)
          $result = $playlists;
      if ($sort == "chrono")
          usort($result, array($this, "sortChrono"));
      else if ($sort == "antechrono" || $sort == null)
      {
          usort($result, array($this, "sortAnteChrono"));
          $sort="antechrono";
      }
      $this-&gt;view-&gt;assignMultiple(array('categorie' =&gt; $categorie, 'list' =&gt; $result, 'sort' =&gt; $sort));
  </code></pre>
  
  <p>Here is my view :</p>
  
  <pre><code>&lt;f:widget.paginate objects="{list}" as="paginatedList" configuration="{addQueryString: 'true', addQueryStringMethod: 'GET,POST', itemsPerPage: 21}"&gt;
      &lt;div class="videos row"&gt;
          &lt;f:for each="{paginatedList}" as="element"&gt;
              &lt;f:render partial="Show/ItemCat" arguments="{item: element}"/&gt;
          &lt;/f:for&gt;
      &lt;/div&gt;
  &lt;/f:widget.paginate&gt;
  </code></pre>
  
  <p>The partial render shows stuff including a picture used as a cover. So I need at least this relation in the view.</p>
  
  <p>This works fine and shows only the items from the category that is requested. Unfortunatly I have a huge performance issue : I tried to show a category that contains more than 3000 records and It takes about one minute to load. It's a <em>little bit</em> long. </p>
  
  <p>By f:debugging my list variable, I see that it contains every records even through it shouldn't be the case (that's the point of pagination...). So the first question is : is there something wrong in the way I did my pagination ?</p>
  
  <p>I tried to simplify my requests by enabling the rawQuery thing ($query->execute(true)) : I get way better performance, but I can't get the link for the pictures (in my view, I get 1 or 0 but not the picture's uid...). Second question : is there a way to fix this issue ?</p>
  
  <p>I hope my description is clear enough. Thanks for your help :-)</p>