Skip to content

fix(cms): homepage latest-pages block returns fewer pages than the configured limit #534

@jbourdin

Description

@jbourdin

Bug

The homepage latestPages block has a "max items" config (limit). When a category contains enough pages, the block still renders fewer pages than the configured limit.

Root cause

PageRepository::findPublishedByCategory() (src/Repository/PageRepository.php:64-83) combines:

  • leftJoin('p.translations', 't')
  • addSelect('t')
  • setMaxResults($limit)

This is the classic Doctrine pitfall: setMaxResults applies LIMIT to SQL rows, not hydrated entities. With 2 translations per page (en + fr), limit=5 produces SQL LIMIT 5 → ~2–3 pages after hydration.

Fix

Use Doctrine\ORM\Tools\Pagination\Paginator (which rewrites the query so LIMIT applies to root entities), or do a two-step query: first fetch IDs with LIMIT, then hydrate entities + translations by IDs.

Files

  • src/Repository/PageRepository.php:64-83findPublishedByCategory()
  • src/Service/HomepageRenderer.php:185-215resolveLatestPages() (caller)

Verification

  1. Create a category with ≥ 10 published pages, each with en and fr translations.
  2. Add a latestPages block with limit = 5 to the homepage.
  3. Confirm exactly 5 pages render.
  4. Add a unit test on PageRepository::findPublishedByCategory asserting count.

Metadata

Metadata

Assignees

No one assigned

    Labels

    bugSomething isn't working

    Projects

    Status

    Done

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions