Skip to content

Add API endpoint for resource milestone events

What does this MR do?

Adds an API endpoint to retrieve resource milestone events for issues and merge requests.

https://gitlab.com/gitlab-org/gitlab/-/issues/216069

Database queries

Test setup

Issue 482 has 319 resource milestone events:

Issue.find(482).resource_milestone_events.count
   (0.7ms)  SELECT COUNT(*) FROM "resource_milestone_events" WHERE "resource_milestone_events"."issue_id" = 482
=> 319

Running the finder in rails console:

[1] pry(main)> user = User.find(1)
  User Load (2.0ms)  SELECT "users".* FROM "users" WHERE "users"."id" = 1 LIMIT 1
=> #<User id:1 @root>
[2] pry(main)> issue = Issue.find(482)
  Issue Load (1.6ms)  SELECT "issues".* FROM "issues" WHERE "issues"."id" = 482 LIMIT 1
  Project Load (3.1ms)  SELECT "projects".* FROM "projects" WHERE "projects"."id" = 7 LIMIT 1
  Route Load (0.8ms)  SELECT "routes".* FROM "routes" WHERE "routes"."source_id" = 7 AND "routes"."source_type" = 'Project' LIMIT 1
=> #<Issue id:482 twitter/typeahead-js#48>
[3] pry(main)> finder = ResourceMilestoneEventFinder.new(user, issue).execute
  ResourceMilestoneEvent Load (4.0ms)  SELECT "resource_milestone_events".* FROM "resource_milestone_events" WHERE "resource_milestone_events"."issue_id" = 482 LIMIT 100 OFFSET 0
  User Load (0.6ms)  SELECT "users".* FROM "users" WHERE "users"."id" = 1
  Milestone Load (1.2ms)  SELECT "milestones".* FROM "milestones" WHERE "milestones"."id" IN (61, 60, 35)
  Project Load (0.9ms)  SELECT "projects".* FROM "projects" WHERE "projects"."id" = 7
  ProjectFeature Load (0.6ms)  SELECT "project_features".* FROM "project_features" WHERE "project_features"."project_id" = 7 LIMIT 1
  Group Load (1.1ms)  SELECT "namespaces".* FROM "namespaces" WHERE "namespaces"."type" = 'Group' AND "namespaces"."id" = 27 AND "namespaces"."type" = 'Group' LIMIT 1
  Group Load (0.6ms)  SELECT "namespaces".* FROM "namespaces" WHERE "namespaces"."type" = 'Group' AND "namespaces"."id" = 27 AND "namespaces"."parent_id" IS NULL LIMIT 1
  SamlProvider Load (0.3ms)  SELECT "saml_providers".* FROM "saml_providers" WHERE "saml_providers"."group_id" = 27 LIMIT 1
Query plans
explain analyze 
SELECT "resource_milestone_events".* 
FROM "resource_milestone_events" 
WHERE "resource_milestone_events"."issue_id" = 482 
LIMIT 100 OFFSET 0
Limit  (cost=0.00..7.44 rows=100 width=52) (actual time=0.032..0.307 rows=100 loops=1)
  ->  Seq Scan on resource_milestone_events  (cost=0.00..23.73 rows=319 width=52) (actual time=0.029..0.274 rows=100 loops=1)
        Filter: (issue_id = 482)
        Rows Removed by Filter: 225
Planning time: 0.408 ms
Execution time: 0.409 ms
explain analyze 
SELECT "milestones".* 
FROM "milestones" 
WHERE "milestones"."id" IN (61, 60, 35)
Seq Scan on milestones  (cost=0.00..4.20 rows=3 width=233) (actual time=0.032..0.044 rows=3 loops=1)
  Filter: (id = ANY ('{61,60,35}'::integer[]))
  Rows Removed by Filter: 58
Planning time: 1.256 ms
Execution time: 0.097 ms

Screenshots

Does this MR meet the acceptance criteria?

Conformity

Availability and Testing

Security

If this MR contains changes to processing or storing of credentials or tokens, authorization and authentication methods and other items described in the security review guidelines:

  • Label as security and @ mention @gitlab-com/gl-security/appsec
  • The MR includes necessary changes to maintain consistency between UI, API, email, or other methods
  • Security reports checked/validated by a reviewer from the AppSec team
Edited by 🤖 GitLab Bot 🤖

Merge request reports

Loading