Skip to content

[2.x] perf(core): mitigate n+1 on notifications index#4817

Closed
DavideIadeluca wants to merge 1 commit into
flarum:2.xfrom
glowingblue:di/notifications-n-plus-1
Closed

[2.x] perf(core): mitigate n+1 on notifications index#4817
DavideIadeluca wants to merge 1 commit into
flarum:2.xfrom
glowingblue:di/notifications-n-plus-1

Conversation

@DavideIadeluca

@DavideIadeluca DavideIadeluca commented Jul 16, 2026

Copy link
Copy Markdown
Contributor

Fixes #0000

Changes proposed in this pull request:

Reviewers should focus on:
Review this along side #4816. Maybe take inspiration from both PR's and create a new PR yourself with a mixture of both fixes and close ours

Screenshot

Necessity

  • Has the problem that is being solved here been clearly explained?
  • If applicable, have various options for solving this problem been considered?
  • For core PRs, does this need to be in core, or could it be in an extension?
  • Are we willing to maintain this for years / potentially forever?

Confirmed

  • Frontend changes: tested on a local Flarum installation.
  • Backend changes: tests are green (run composer test).
  • Core developer confirmed locally this works as intended.
  • Tests have been added, or are not appropriate here.

Required changes:

  • Related documentation PR: (Remove if irrelevant)

@DavideIadeluca DavideIadeluca changed the title perf(core): mitigate n+1 on notifications index [2.x] perf(core): mitigate n+1 on notifications index Jul 16, 2026
@DavideIadeluca
DavideIadeluca marked this pull request as ready for review July 16, 2026 14:22
@DavideIadeluca
DavideIadeluca requested a review from a team as a code owner July 16, 2026 14:22
@imorland

Copy link
Copy Markdown
Member

Superseded by #4828, which combines this with #4816 and adds a query-count test for the n+1. Thanks!

@imorland imorland closed this Jul 23, 2026
imorland added a commit that referenced this pull request Jul 23, 2026
… n+1 (#4828)

Gate the `subject.discussion` default include on whether a subject type
actually exposes a `discussion` relationship, instead of on the number of
subject types. The old count-based check added an invalid include when the
extra types had no such relationship (e.g. a User-subject notification with
no Post-subject type present), which the include validator rejected with a
400 for every request, breaking the notifications dropdown and page.

Also eager-load the polymorphic subject's `state` / `discussion.state` so
the index no longer issues a query per notification for them.

Combines #4816 and #4817.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants