Skip to content

fix: find the first slice of an article with a single query - #6790

Merged
gharlan merged 2 commits into
6.xfrom
perf/first-slice-single-query
Oct 21, 2026
Merged

gharlan merged 2 commits into
6.xfrom
perf/first-slice-single-query

Conversation

@gharlan

@gharlan gharlan commented Oct 21, 2026

Copy link
Copy Markdown
Member

ArticleSlice::getFirstSliceForArticle() queried the content sections 1 to 20 one by one — up to 20 queries per call, and slices in content sections above 20 were never found. It now uses a single query and relies on the existing ORDER BY content_section_id, priority LIMIT 1 (covered by the find_slices index).

While at it, $ignoreOfflines is fixed in both getFirstSliceForArticle() and getFirstSliceForContentSection(): they filtered by priority = 1 AND status = 1, so an offline first slice made them return null (or skip the whole content section) even if online slices followed. getNextSlice() already handled this correctly.

The docblock of getFirstSliceForArticle() no longer claims that getNextSlice() iterates over all slices of the article — it stays within the content section.

The new tests fail on the old implementation.

`getFirstSliceForArticle()` queried the content sections 1 to 20 one by one, so it needed up to 20 queries and
missed slices in sections above 20. It now relies on the ordering by content section and priority instead.

Both `getFirstSliceForArticle()` and `getFirstSliceForContentSection()` required `priority = 1`, so with
`$ignoreOfflines` they returned no slice (or skipped the whole section) if the first slice was offline.
@gharlan gharlan added this to the REDAXO 6.0 milestone Oct 21, 2026
@rex-bot rex-bot added the bug label Oct 21, 2026
@gharlan
gharlan enabled auto-merge (squash) October 21, 2026 22:17
@gharlan
gharlan merged commit a730cfa into 6.x Oct 21, 2026
15 checks passed
@gharlan
gharlan deleted the perf/first-slice-single-query branch October 21, 2026 22:18
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

Development

Successfully merging this pull request may close these issues.

2 participants