Fix Enable Mastodon Apps notification pagination by using date-constrained queries#3150
Merged
Fix Enable Mastodon Apps notification pagination by using date-constrained queries#3150
Conversation
The api_notifications_get handler was applying array_slice() to the full accumulated notifications array using the request's limit parameter. This caused incorrect pagination: handlers injecting notifications at earlier filter priorities (< 10) would have their items truncated before finalize_notifications() could apply proper max_id/min_id pagination. EMA now passes $limit, $before_date, and $after_date as additional filter arguments (backward compatible — existing 2-arg handlers are unaffected). When $before_date or $after_date is provided, the handler uses date_query constraints on get_comments() and Followers::get_many() to fetch only the relevant window, keeping queries bounded without truncating the full pool.
There was a problem hiding this comment.
Pull request overview
Note
Copilot was unable to run its full agentic suite in this review.
Fixes pagination issues in EMA’s notifications aggregation by avoiding premature sorting/truncation and instead constraining source queries by a pagination-derived date window.
Changes:
- Expands the
mastodon_api_notifications_getfilter to accept$limit,$before_date, and$after_date(while keeping older handlers compatible). - Switches comment/follower notification fetching to optionally use
date_querywhen a pagination window is present. - Removes in-handler
usort()+array_slice()sofinalize_notifications()can paginate the full merged set correctly.
Reviewed changes
Copilot reviewed 2 out of 2 changed files in this pull request and generated 3 comments.
| File | Description |
|---|---|
| integration/class-enable-mastodon-apps.php | Extends filter args; uses date-constrained queries for comment/follow notifications; removes premature truncation. |
| .github/changelog/3150-from-description | Adds changelog entry describing the pagination fix and new filter args. |
- Add build_date_query() to avoid duplicated date_query construction - Use it in both get_comments and Followers::get_many paths - Remove the $limit = -1 override when date constraints are set; the caller-provided $limit now caps both paths consistently
pfefferle
approved these changes
Apr 7, 2026
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Problem
api_notifications_getwas callingarray_slice( $notifications, 0, $limit )on the full accumulated notifications array. This broke pagination in two ways:finalize_notifications()could apply propermax_id/min_idpagination.finalize_notifications()ran.Solution
EMA now passes three additional arguments to the
mastodon_api_notifications_getfilter:$limit— the clamped page size$before_date— derived frommax_id, or null$after_date— derived frommin_id/since_id, or nullThis is backward compatible — existing handlers registered with
add_filter( ..., 10, 2 )receive only the first two arguments and are unaffected.When
$before_dateor$after_dateis provided, this handler switches to date-constrained queries (date_queryonget_comments(),date_queryonFollowers::get_many()) so the fetch is bounded to the relevant pagination window without truncating the shared pool. When no date window is set (first page), it falls back to$limitas before.Test plan
max_idreturns the correct next pageChangelog entry
Changelog Entry Details
Significance
Type
Message
Fix notification pagination when using Enable Mastodon Apps: use date-constrained queries instead of truncating the shared notification pool, and expose
$limit,$before_date, and$after_dateas additional filter arguments so third-party handlers can fetch the correct window.