Skip to content

Add user and system note filters to note_authors association

What does this MR do and why?

On occasion we want to be able to filter authors of system vs user notes. These allow us to filter the results in a single query.

[2] pry(main)> mr.note_authors
  User Load (20.7ms)  SELECT DISTINCT "users".* FROM "users" INNER JOIN "notes" ON "users"."id" = "notes"."author_id" WHERE "notes"."noteable_id" = 219 AND "notes"."noteable_type" = 'MergeRequest'
=> [#<User id:1 @root>, #<User id:191 @kerrizor>]
[3] pry(main)> mr.note_authors.user_notes
  User Load (1.7ms)  SELECT DISTINCT "users".* FROM "users" INNER JOIN "notes" ON "users"."id" = "notes"."author_id" WHERE "notes"."noteable_id" = 219 AND "notes"."noteable_type" = 'MergeRequest' AND (notes.system = false) 
=> [#<User id:1 @root>]
[4] pry(main)> mr.note_authors.system_notes
  User Load (1.5ms)  SELECT DISTINCT "users".* FROM "users" INNER JOIN "notes" ON "users"."id" = "notes"."author_id" WHERE "notes"."noteable_id" = 219 AND "notes"."noteable_type" = 'MergeRequest' AND (notes.system = true) 
=> [#<User id:191 @kerrizor>]
[5] pry(main)>

MR acceptance checklist

This checklist encourages us to confirm any changes have been analyzed to reduce risks in quality, performance, reliability, security, and maintainability.

Related to #353387 (closed)

Edited by Kerri Miller

Merge request reports