Simplify milestone / epic date-handling code
Follow-up for https://gitlab.com/gitlab-org/gitlab-ee/merge_requests/6448.
We need to set the milestone date and milestone ID for epics. We need to recompute these when a milestone date is updated, an issue has its milestone updated, an epic has an issue added to it, or an epic has an issue deleted from it.
This has lead to some complicated code. In the existing MR, we didn't see a way around this, but maybe fresh eyes and the benefit of time will help. These can be separate issues, but for now, I'm creating them as one issue:
- The name
DateSourcingMilestonesFinder
is a bit convoluted (https://gitlab.com/gitlab-org/gitlab-ee/merge_requests/6448#note_92436551)- The finder itself might not be the right type of class for this, as it builds a query and returns column values, not ActiveRecord objects (https://gitlab.com/gitlab-org/gitlab-ee/merge_requests/6448/diffs#note_92849483).
- (Minor.) There is a large query written in SQL, which probably could be expressed in ActiveRecord (https://gitlab.com/gitlab-org/gitlab-ee/merge_requests/6448#note_92695494).
-
Epic.update_start_and_due_dates
is also quite complicated.- To make the updates more efficient, we group epics with the same set of milestones together (https://gitlab.com/gitlab-org/gitlab-ee/merge_requests/6448#note_92695856) - this in itself is fiddly.
- Ideally, we could write one
UPDATE
statement and move much of the computation to SQL. This might not be possible, though.