VSA Add `last_approved_at` Event
What does this MR do and why?
This merge request updates the GitLab database by adding a new table called merge_request_approval_metrics
and a corresponding migration. The new table will store approval metrics for merge requests, including the last approval timestamp. This change will provide additional insights into the approval process of merge requests.
This MR will involve:
- Creating a new table
- Persisting the data of
last_approved_at
of an MR intomerge_request_approval_metrics
References
MR acceptance checklist
- Start GitLab project locally
- In any MR in any project, approve the MR via the same account multiple times and via other accounts too
- After every MR approval, do the following:
- Open a rails console:
bin/rails console
- Fetch the approval metric of this MR:
MergeRequest::ApprovalMetrics.find_by(merge_request_id: your_MR_ID)
- You can find MR id in the URL - With every approval,
last_approved_at
should be updated to the latest approval - If it doesn't update, check if sidekiq jobs are processed correctly via sidekiq dashboard
http://gdk.test:3000/admin/sidekiq
- Fetch the approval metric of this MR:
SQL Query and SQL Execution Plan:
MergeRequest::ApprovalMetrics.refresh_last_approved_at(6)
:
Query:
MergeRequest::ApprovalMetrics Upsert (0.2ms) INSERT INTO "merge_request_approval_metrics" ("merge_request_id","last_approved_at") VALUES (6, '2024-12-19 11:14:09.775815') ON CONFLICT ("merge_request_id") DO UPDATE SET "last_approved_at"=excluded."last_approved_at" RETURNING "merge_request_id
Execution Plan:
[
{
"Plan": {
"Node Type": "ModifyTable",
"Operation": "Insert",
"Parallel Aware": false,
"Async Capable": false,
"Relation Name": "merge_request_approval_metrics",
"Alias": "merge_request_approval_metrics",
"Startup Cost": 0.00,
"Total Cost": 0.01,
"Plan Rows": 0,
"Plan Width": 0,
"Actual Startup Time": 0.427,
"Actual Total Time": 0.428,
"Actual Rows": 0,
"Actual Loops": 1,
"Conflict Resolution": "UPDATE",
"Conflict Arbiter Indexes": ["merge_request_approval_metrics_pkey"],
"Tuples Inserted": 0,
"Conflicting Tuples": 1,
"Plans": [
{
"Node Type": "Result",
"Parent Relationship": "Outer",
"Parallel Aware": false,
"Async Capable": false,
"Startup Cost": 0.00,
"Total Cost": 0.01,
"Plan Rows": 1,
"Plan Width": 16,
"Actual Startup Time": 0.002,
"Actual Total Time": 0.002,
"Actual Rows": 1,
"Actual Loops": 1
}
]
},
"Planning Time": 0.236,
"Triggers": [
],
"Execution Time": 0.483
}
]
Related to #509062
Edited by Amr Taha