Limit pending draft notes per user on a merge request
What does this MR do and why?
A user who can comment on a merge request can add any number of unpublished draft notes to it. DraftNote checks the size of each note, but not how many there are, so one user can keep adding rows to draft_notes on any merge request they can comment on, and nothing removes them.
This adds a draft_notes_per_merge_request plan limit, 200 by default, and enforces it in DraftNote through Limitable. The limit counts the drafts of the same author on the same merge request, so other reviewers and other merge requests are not affected. When a user reaches the limit, they must submit or discard their review before they add more drafts. It follows the other plan limits: the admin plan limits API exposes it, and 0 disables it.
Database
large amount of drafts on a merge request
SELECT 1 AS one FROM draft_notes WHERE draft_notes.merge_request_id = 432380421 AND draft_notes.author_id = 1 LIMIT 1 OFFSET 199;https://console.postgres.ai/gitlab/projects/gitlab-production-main/sessions/79102/commands/187443
smaller amount of drafts on a merge request
SELECT 1 AS one FROM draft_notes WHERE draft_notes.merge_request_id = 400029340 AND draft_notes.author_id = 21576503 LIMIT 1 OFFSET 199;https://console.postgres.ai/gitlab/projects/gitlab-production-main/sessions/79102/commands/187444
References
https://gitlab.com/gitlab-org/gitlab/-/work_items/636471
Screenshots or screen recordings
| Before | After |
|---|---|
MR acceptance checklist
Evaluate this MR against the MR acceptance checklist. It helps you analyze changes to reduce risks in quality, performance, reliability, security, and maintainability.