Skip to content

Delegate reading `subscriptions` for synced work item epics

What does this MR do and why?

Related to #443546 (closed)

Unify subscriptions from epics and work item epics. When querying the subscriptions from a legacy epic, the synced work item's subscriptions are returned too. For example:

[1] pry(main)> epic = Epic.last
[2] pry(main)> epic.subscriptions
 # => ...
Subscription Load (1.4ms)  SELECT "subscriptions".* FROM ((SELECT "subscriptions".* FROM "subscriptions" WHERE "subscriptions"."subscribable_id" = 738 AND "subscriptions"."subscribable_type" = 'Issue')
UNION
(SELECT "subscriptions".* FROM "subscriptions" WHERE "subscriptions"."subscribable_id" = 228 AND "subscriptions"."subscribable_type" = 'Epic')) subscriptions /*application:console,db_config_name:main,console_hostname:Eugenias-MacBook-Pro-2.local,console_username:eugenia,line:/ee/app/models/concerns/work_items/epic_as_work_item.rb:60:in `load_target'*/

The same applies to querying subscriptions for the synced work item:

[3] pry(main)> epic.work_item.subscriptions
#=> ...
Subscription Load (0.6ms)  SELECT "subscriptions".* FROM ((SELECT "subscriptions".* FROM "subscriptions" WHERE "subscriptions"."subscribable_id" = 228 AND "subscriptions"."subscribable_type" = 'Epic')
UNION
(SELECT "subscriptions".* FROM "subscriptions" WHERE "subscriptions"."subscribable_id" = 738 AND "subscriptions"."subscribable_type" = 'Issue')) subscriptions /*application:console,db_config_name:main,console_hostname:Eugenias-MacBook-Pro-2.local,console_username:eugenia,line:/ee/app/models/concerns/work_items/epic_as_work_item.rb:60:in `load_target'*/

When checking if a user is subscribed to the epic, this returns true when the user is only subscribed to the work item (and vice versa). Example:

[4] pry(main)> user = User.first
[5] pry(main)> epic.subscribed?(user) #=> true
[6] pry(main)> epic.work_item.subscribed?(user) #=> true

In the case of a record existing for both the epic and the work item, we check the state of the latest one.

When changing the subscription we check if a record exists for either the epic or the work item and update it when found. When no subscription record exists a new one is created for the subscribable object.

[2] pry(main)> epic.subscriptions
[3] pry(main)> epic.subscribed?(User.first) #=> true
[4] pry(main)> epic.work_item.subscribed?(User.first) #=> true
[5] pry(main)> epic.work_item.set_subscription(User.first, false)
[6] pry(main)> epic.subscribed?(User.first) #=> false
[7] pry(main)> epic.work_item.subscribed?(User.first) #=> false

These changes are added behind the FF epic_and_work_item_associations_unification.

Database

Queries when reading the subscription

Queries for checking if a user is subscribed

MR acceptance checklist

Please evaluate this MR against the MR acceptance checklist. It helps you analyze changes to reduce risks in quality, performance, reliability, security, and maintainability.

Screenshots or screen recordings

If you need help visually verifying the change, please leave a comment and ping a GitLab reviewer, maintainer, or MR coach. -->

Subscription exists on legacy epic Subscription exists on synced work item
subscription_on_epic subscription_on_work_item
Edited by Eugenia Grieff

Merge request reports