Solved thread

This post is marked as solved. If you think the information contained on this thread must be part of the official documentation, please contribute submitting a pull request to its repository.

ODM Find() is slow with 10k records


I have a collection called reviews. Inside this collection, I have 10,000+ documents. When I do a find() and use paginator, the page loads quite slow.

I think is because I have too many documents. How can I optimize this,

 $reviews_res = Reviews::find();

  $paginator = new \Phalcon\Paginator\Adapter\NativeArray(
            "data" => $reviews_res,
            "limit"=> 18,
            "page" => $currentPage

    $reviewslistpaginated = $paginator->getPaginate();

Advice appreciated. :D

edited May '17

Hey friend,

first of all, ODM/ORM's will always be slower than normal quries. In your case you are selecting all 10k records and paginate them with NativeArray adaptor, its like doing array_chunk on huge array...

I would recommend to rewrite the query with QueryBuilder and use the appropriate adapter:


Don't use paginator, just use find:

 $reviews_res = Reviews::find([
     'limit' => '18',
     'skip' => $currentPage*18 - 18

I guess we need paginator adapter for collection, can you create issue on github?

Collection doesn't have query builder, right ? :D

Ohhhh I'm talking nonsence! Thank you for the correction Wojciech :)