recipe_improve_performance_large_datasets.rst 2.1 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152
  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 milions 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. <!-- Acme/DemoBundle/Resources/config/admin.xml -->
  16. <container xmlns="http://symfony.com/schema/dic/services"
  17. xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
  18. xsi:schemaLocation="http://symfony.com/schema/dic/services/services-1.0.xsd">
  19. <services>
  20. <service id="sonata.admin.post" class="Acme\DemoBundle\Admin\PostAdmin">
  21. <tag name="sonata.admin" manager_type="orm" group="Content" label="Post" pager_type="simple" />
  22. <argument />
  23. <argument>Acme\DemoBundle\Entity\Post</argument>
  24. <argument />
  25. </service>
  26. </services>
  27. </container>
  28. .. code-block:: yaml
  29. # Acme/DemoBundle/Resources/config/admin.yml
  30. services:
  31. sonata.admin.post:
  32. class: Acme\DemoBundle\Admin\PostAdmin
  33. tags:
  34. - { name: sonata.admin, manager_type: orm, group: "Content", label: "Post", pager_type: "simple" }
  35. arguments:
  36. - ~
  37. - Acme\DemoBundle\Entity\Post
  38. - ~
  39. .. note:: The `pager_results` template is automatically changed to `SonataAdminBundle:Pager:simple_pager_results.html.twig` if it's not already overloaded.