I had implemented the zf2 paginator. But now as the data increased I realized it is fetching all records first and then the pagination takes place, which takes more time. I did not realize the speed issue until the records went more than 1k.
Does the paginator really works like this, or I am missing something in my code ?
$photos = $em->getRepository('User\Entity\MyEntity')->findBy(array('id' => $main_id, 'status' => '1', 'is_primary' => '1'));
/** Create Paginator * */
$paginator = new \Zend\Paginator\Paginator(new
\Zend\Paginator\Adapter\ArrayAdapter($photos)
);
if (isset($data['pg_id'])) {
$paginator->setCurrentPageNumber($data['pg_id']);
} else {
$paginator->setCurrentPageNumber(1);
}
$paginator->setDefaultItemCountPerPage(25);