Skip to content

Fix Enable Mastodon Apps notification pagination by using date-constrained queries#3150

Merged
pfefferle merged 4 commits intotrunkfrom
fix/ema-notifications-pagination
Apr 7, 2026
Merged

Fix Enable Mastodon Apps notification pagination by using date-constrained queries#3150
pfefferle merged 4 commits intotrunkfrom
fix/ema-notifications-pagination

Conversation

@akirk
Copy link
Copy Markdown
Member

@akirk akirk commented Apr 7, 2026

Problem

api_notifications_get was calling array_slice( $notifications, 0, $limit ) on the full accumulated notifications array. This broke pagination in two ways:

  1. Any handler injecting notifications at a filter priority lower than 10 would have its items truncated before finalize_notifications() could apply proper max_id/min_id pagination.
  2. The sort+slice happened before all sources had contributed, so the final merged set was already incomplete when finalize_notifications() ran.

Solution

EMA now passes three additional arguments to the mastodon_api_notifications_get filter:

  • $limit — the clamped page size
  • $before_date — derived from max_id, or null
  • $after_date — derived from min_id/since_id, or null

This is backward compatible — existing handlers registered with add_filter( ..., 10, 2 ) receive only the first two arguments and are unaffected.

When $before_date or $after_date is provided, this handler switches to date-constrained queries (date_query on get_comments(), date_query on Followers::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 $limit as before.

Test plan

  • Verify existing EMA notification tests pass
  • Manually verify reblog/like/follow notifications appear correctly on first page
  • Manually verify paginating through notifications with max_id returns the correct next page

Changelog entry

  • Automatically create a changelog entry from the details below.
Changelog Entry Details

Significance

  • Patch
  • Minor
  • Major

Type

  • Added - for new features
  • Changed - for changes in existing functionality
  • Deprecated - for soon-to-be removed features
  • Removed - for now removed features
  • Fixed - for any bug fixes
  • Security - in case of vulnerabilities

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_date as additional filter arguments so third-party handlers can fetch the correct window.

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.
Copilot AI review requested due to automatic review settings April 7, 2026 08:05
@github-actions github-actions bot added the [Focus] Compatibility Ensuring the plugin plays well with other plugins label Apr 7, 2026
Copy link
Copy Markdown

Copilot AI left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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_get filter to accept $limit, $before_date, and $after_date (while keeping older handlers compatible).
  • Switches comment/follower notification fetching to optionally use date_query when a pagination window is present.
  • Removes in-handler usort() + array_slice() so finalize_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.

@akirk akirk added [Focus] Compatibility Ensuring the plugin plays well with other plugins and removed [Focus] Compatibility Ensuring the plugin plays well with other plugins labels Apr 7, 2026
@akirk akirk changed the title Fix EMA notification pagination by using date-constrained queries Fix Enable Mastodon Apps notification pagination by using date-constrained queries Apr 7, 2026
akirk added 2 commits April 7, 2026 11:52
- 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 pfefferle merged commit 27528df into trunk Apr 7, 2026
10 checks passed
@pfefferle pfefferle deleted the fix/ema-notifications-pagination branch April 7, 2026 19:06
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

[Focus] Compatibility Ensuring the plugin plays well with other plugins

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants