-
-
Notifications
You must be signed in to change notification settings - Fork 6.9k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Add experimental server-side notification grouping #29889
Conversation
b44af10
to
8259dfd
Compare
8b7f171
to
ad2aebf
Compare
ad2aebf
to
16374e4
Compare
While this PR is still exploratory, this approach is promising. The Arel patch has been accepted into ActiveRecord, so the only monkey-patch left is the recursive CTE one. On that topic, @lorint, I've used the code you published here to validate the approach, but I have to double-check whether you are ok for this to be included in Mastodon (AGPLv3) or Rails (MIT). Furthermore, are you interested in trying to get this feature merged upstream yourself, or do you prefer I try to do it? |
8e2ba0b
to
ee09aa6
Compare
ee09aa6
to
a50b871
Compare
I think this is ready for review, with the understanding that the API is experimental for now (hence the cc @mjankowski if you can have a quick look at the implementation. |
Some questions before I get into any detailed code review...
|
Yes. We might discontinue
Yes.
The UI work has not started yet. |
Great, noted on API preview expectations and migration path. The lack of UI work makes it sort of challenging to review the approach, since there's not a use case or design to support it seems a little speculative, rather than emerging from a need of a feature? If we're doing alpha/preview just to put actual endpoints up for clients to experiment with ... could we literally just hardcode some JSON showing the proposed new response, and get feedback from client devs? Or if there's internal WIP for the web client, leave this in draft until that's further along? |
ee0d1e1
to
5a8f729
Compare
This pull request has merge conflicts that must be resolved before it can be merged. |
Re-use recently-used groups as long as they don't span over more than 12 hours
… pages are requested
…ages are requested
5a8f729
to
16ccc53
Compare
This pull request has resolved merge conflicts and is ready for review. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I am fine with merging this.
The database side should not change now, and the API is marked as experimental, so I do not expect problems deploying it.
We can change the API in further PRs until we mark it as stable if needed, and having it merged will make working on the frontend implementation much easier and less prone to rebase issues.
@mjankowski I marked your conversations as resolved in order to move forward, but there's a couple refactors that may still be worth exploring:
|
This PR adds a
group_key
attribute on theNotification
model that is filled when creating the notification and is used to allow efficient pagination, fetching no more than one notification per group from the database.It also adds an experimental API:
GET /api/v2_alpha/notifications
GET /api/v2_alpha/notifications/:group_key
POST /api/v2_alpha/notifications/:group_key/dismiss
This relies on a recursive CTE, which is currently not possible to write with stock ActiveRecord, and therefore relies on a couple monkey-patches:
ActiveRecord::QueryMethods
to add support for recursive CTEs through awith_recursive
method, inspired by the one from @lorint (Recursive + 7.1 vlado/activerecord-cte#16 (comment)), and submitted in Rails: Add support for recursive CTEs in ActiveRecord rails/rails#51601Arel::Visitors::ToSql
to address an issue (Arel union with "limit" or "order by" generates invalid SQL rails/rails#40181) that causedarel
to output incorrect SQL for our recursive CTE because of the use ofLIMIT
, now merged upstream: Fixes/union select parentheses rails/rails#51549These patches allow to write the CTE in a pretty readable fashion, and allowing the use of already-defined scopes. This can be used to build an API that returns a page of notifications with no more than one notification per group, and still returns a good number of groups, instead of having to call the notification API repeatedly to possibly get more than one group worth of notifications.
Caveats
because of the monkey-patches, this introduces a fairly high maintenance burden.That being said, one of the two patches has been merged upstream, and the other one is under consideration.
EDIT: both patches have been adopted upstream, so we won't have a long-term maintenance burden