Add new properties to `GET /users/:user_id/projects`
What does this MR do and why?
Related to #378679 (closed)
In &9056 we are in the process of migrating the user profile tabs from HAML/jQuery to Vue. I am currently working on building out the Personal projects
section. This section uses the GET /users/:user_id/projects
endpoint as the data source but we are missing a few attributes we need for the UI.
This MR adds the following attributes to the API:
updated_at
open_merge_requests_count
description_html
Performance
Disclaimer: API performance is a bit above my comfort level so if you have suggestions on better ways to test this or other performance improvements let me know
Using the performance bar I hit the API endpoint with and without these attributes. I didn't notice any extra queries.
To inspect the API request I added the following to app/assets/javascripts/pages/users/show/index.js.
import { getUserProjects } from '~/rest_api';
getUserProjects(1, '', {}, (data) => {
console.log(data);
});
I then reloaded navigated to the user profile and choose the GET projects
request from the performance bar dropdown.
Before | After |
---|---|
How to set up and validate locally
- Add the following to app/assets/javascripts/pages/users/show/index.js
import { getUserProjects } from '~/rest_api';
getUserProjects(1, '', {}, (data) => {
console.log(data);
});
- Open the dev tools and navigate to the user profile. The result of the API request will be logged in the console and you can also inspect the request in the performance bar
Query plan
Existing query (related code):
SELECT COUNT(*) AS count_all, merge_requests.target_project_id AS merge_requests_target_project_id FROM merge_requests WHERE (merge_requests.state_id IN (1)) AND merge_requests.target_project_id IN (35819401, 26005919, 39066644, 20685039, 40646589, 15054799, 8172164, 14503185, 12774390, 17067156, 12774395, 12774391, 8408449, 12774399, 8408433, 41482959, 41482948, 12774363, 8408448, 41482950, 12774398, 5602687, 8408460, 8408422, 8408453, 7003213, 8408464, 8408429, 8408463, 8408400) GROUP BY merge_requests.target_project_id;
Link to query plan: https://console.postgres.ai/gitlab/gitlab-production-tunnel-pg12/sessions/17745/commands/59192
MR acceptance checklist
This checklist encourages us to confirm any changes have been analyzed to reduce risks in quality, performance, reliability, security, and maintainability.
-
I have evaluated the MR acceptance checklist for this MR.