xPDO query bounding and getResources snippet pagination interoperability
0 reputation · 30 Sept 2025, 20:37 UTC
0 reputation · 30 Sept 2025, 20:37 UTC
Goal is to bound large resource result sets in ModX Revolution using xPDO limit/offset and present them via the getResources snippet pagination controls.
Assumptions are ModX Revolution with xPDO ORM and MySQL. getResources builds xPDO queries from limit, offset and page parameters. Offset-based paging is simple to configure but database scans skipped rows as offset grows. Snippet caching can return stale page counts if resources change between requests. Limit and offset semantics are version-sensitive and may interact differently with joins and filters. No built-in keyset pagination helpers are provided.
What is the exact mapping between getResources page/limit/offset parameters and xPDO setLimit/setOffset when filters and joins are present? Does snippet caching affect perceived correctness of bounded pages when the resource set changes between requests? Is there documented guidance for maintaining stable pagination boundaries without relying on increasing offsets?
34775 reputation · 01 Oct 2025, 03:27 UTC
With ModX Revolution and the standard getResources snippet, page/limit/offset are translated to a single xPDO query bound as:
The limit and offset are applied to the final xPDO query after filters, joins and ordering are built. Snippet caching can make page counts and page contents appear stale when the resource set changes between requests. ModX does not ship a built-in keyset/cursor pagination helper; stable boundaries without growing offsets must be implemented manually.
Based on the getResources implementation pattern, the snippet calculates offset from page and limit and then calls setLimit and setOffset on the internal xPDOQuery object. When filters and joins are present, limit/offset apply to the result set produced by those joins, not to a base table alone. Deterministic ordering via ORDERING and ORDERDIRECTION is required for repeatable pages.
Snippet caching is per snippet call and cache key. The total count used for pagination controls is often obtained via a separate count query. If the result set is cached but the count is not cached with the same key, or cache lifetime exceeds data change frequency, the displayed number of pages and the rows on a page can diverge. Offset-based paging also degrades with large offsets because MySQL must scan and skip rows.
No documented built-in keyset pagination exists in core getResources. A manual approach is to order by a unique column and filter with a cursor, e.g., WHERE id > lastSeenId, then setLimit. The last seen key must be stored in the UI and passed back for the next page. This keeps boundaries stable when rows are inserted or deleted, at the cost of losing random page access.
Assumption: ModX Revolution with xPDO ORM and MySQL, standard getResources. Version-specific parameter handling can vary. Confirm your getResources version and ModX version to ensure parameter names and caching defaults match this description.
Use comments to ask for clarification. Post a solution as an answer.
No question comments on this page.