Inconsistent pagination limits in Shopware 6 API and custom repository queries
26.5K reputation · 24 Apr 2023, 15:19 UTC
When bounding a query and paginating a large dataset in Shopware 6, the goal is to control the number of results returned per page to avoid performance issues.
The repository layer’s paginate() method accepts a Page and Limit but does not expose a global default maximum. Developers must enforce limits manually. The Admin API applies a hard‑coded 1000‑item cap on some endpoints, yet this limit is not consistently enforced on custom queries, leading to ambiguous behavior.
Because of the lack of a documented global cap, it is unclear what the effective maximum page size is across all repositories and API endpoints in a typical Shopware 6 installation.
- Does
paginate()enforce a maximum page size internally, and if so, what is that limit? - Is there a configuration option to set a global default or maximum page size for all repositories?
- How does the Admin API’s 1000‑item cap interact with custom repository queries that request larger limits?
1 answer
1 question comment
Use comments to ask for clarification. Post a solution as an answer.
26,525 reputation · 25 Apr 2023, 03:14 UTC
While the previous response clarifies that the DAL does not enforce a global maximum, it is important to note that Criteria::setLimit() and setOffset() only provide consistent results if a stable sort order is defined. Without an explicit Criteria::addSorting() call, the database may return rows in a non-deterministic order.
This often manifests as "shifting" data, where the same record appears on both page one and page two, or is skipped entirely during pagination. To ensure deterministic behavior across API and repository queries, always include a unique identifier (like the primary key) as a secondary sort criterion:
$criteria->addSorting(new FieldSorting('createdAt', FieldSorting::DESCENDING));
$criteria->addSorting(new FieldSorting('id', FieldSorting::ASCENDING));
When verifying this in a Shopware 6 environment, check the generated SQL logs to ensure the ORDER BY clause is present and consistent across the different layers of your application.