recipe_improve_performance_large_datasets.rst 1.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748
  1. Improve performance of large datasets
  2. =====================================
  3. If your database table contains thousands of records, the database queries generated
  4. by SonataAdmin may become very slow. Here are tips how to improve the performance of your admin.
  5. Change default Pager to SimplePager
  6. -----------------------------------
  7. Default `Pager` is counting all rows in the table, so user can easily navigate
  8. to any page in the Datagrid. But counting thousands or millions of records
  9. can be slow operation. If you don't need to know the number of all records,
  10. you can use `SimplePager` instead. It doesn't count all rows, but gives user only
  11. information if there is next page or not.
  12. To use `SimplePager` in your admin just define ``pager_type`` inside the service definition:
  13. .. configuration-block::
  14. .. code-block:: xml
  15. <!-- src/AppBundle/Resources/config/admin.xml -->
  16. <service id="app.admin.post" class="AppBundle\Admin\PostAdmin">
  17. <tag name="sonata.admin" manager_type="orm" group="Content" label="Post" pager_type="simple" />
  18. <argument />
  19. <argument>AppBundle\Entity\Post</argument>
  20. <argument />
  21. </service>
  22. .. code-block:: yaml
  23. # src/AppBundle/Resources/config/admin.yml
  24. services:
  25. app.admin.post:
  26. class: AppBundle\Admin\PostAdmin
  27. tags:
  28. - { name: sonata.admin, manager_type: orm, group: "Content", label: "Post", pager_type: "simple" }
  29. arguments:
  30. - ~
  31. - AppBundle\Entity\Post
  32. - ~
  33. public: true
  34. .. note::
  35. The ``pager_results`` template is automatically changed to ``SonataAdminBundle:Pager:simple_pager_results.html.twig`` if it's not already overloaded.