Use mention tables for calculating recipients, and allow filtering by subscribed issues
Everyone can contribute. Help move this issue forward while earning points, leveling up and collecting rewards.
After we have done https://gitlab.com/gitlab-org/gitlab-ce/issues/45125 and https://gitlab.com/gitlab-org/gitlab-ce/issues/45126, we can use the new table(s) to calculate who should receive an email.
-
Address specs adjustments that might be needed to ensure #36381
We can also use them to allow users to filter by issues that they are participating in, in some capacity.
Quoting from https://gitlab.com/gitlab-org/gitlab-ce/issues/12697#note_31827960:
To create/remove a subscription you then need to get the issue/MR ID, get the corresponding note IDs, then get the mentioned user IDs. For every ID you then have to make sure a subscription exists, or is removed in case a user is no longer mentioned. The query to get the data would be something like:
SELECT user_id, COUNT(user_id) AS mention_count FROM note_username_mentions WHERE EXISTS ( SELECT true FROM notes WHERE noteable_type = 'Issue' AND noteable_id = CURRENT_ISSUE_ID AND note_username_mentions.note_id = notes.id ) GROUP BY user_id
To create subscriptions you'd basically do this every time you save a note:
Lock the issue
Get the mentioned users/counts using the above query
Save the note and update the mentions table according to the mentioned usernames (don't just wipe all rows then re-add them, this creates a ton of bloat)
Update the results of the query from step 2 in memory
For new users add subscriptions, for user IDs with
mention_count == 0
remove the subscriptionUnlock the issue
This is a rough outline of what I think would be necessary. The big problem here is locking the issue as this will prevent:
Others from editing the issue (even doing simple things such as labelling it)
Others from posting comments
There might be ways to use less aggressive locking, but at some point you'll need to get a consistent overview of who's currently mentioned without that list getting modified while you're doing your work.
In short, it's complex.