Display labels in abuse reports list page
What does this MR do and why?
Implements https://gitlab.com/gitlab-org/modelops/anti-abuse/team-tasks/-/issues/451+.
This MR updates abuse reports list page to display labels assigned to each report.
Note: clicking on displayed labels on the list page adds the selected label title as a label_name[]=
query param to the URL but this does not filter the list yet. Filtering will be implemented in https://gitlab.com/gitlab-org/modelops/anti-abuse/team-tasks/-/issues/448+.
Database changes
When fetching abuse report records to display on the abuse reports list page, two additional queries are introduced to include labels:
# taken from log/development.log
# existing query
AbuseReport Load (0.5ms) SELECT aggregated.*, status, id, reporter_id, created_at, updated_at FROM (SELECT user_id, category, COUNT(id) as count, MIN(id) as min FROM "abuse_reports" WHERE "abuse_reports"."status" = 1 GROUP BY "abuse_reports"."user_id", "abuse_reports"."category") aggregated INNER JOIN abuse_reports on aggregated.min = abuse_reports.id WHERE "abuse_reports"."status" = 1 AND "abuse_reports"."status" = 1 ORDER BY "count" DESC, "created_at" DESC LIMIT 20 OFFSET 0
# new query
LabelLink Load (0.2ms) SELECT "label_links".* FROM "label_links" WHERE "label_links"."target_type" = 'AbuseReport' AND "label_links"."target_id" IN (23, 22, 21, 20, 19, 18, 17, 16, 15, 14, 13, 12, 11, 10, 9, 8, 7, 6, 5, 4)
# new query
Label Load (0.2ms) SELECT "labels".* FROM "labels" WHERE "labels"."id" IN (111, 112, 113) ORDER BY "labels"."title" ASC
LabelLink
Query 1: EXPLAIN: https://console.postgres.ai/shared/fcd82c72-1cfc-4889-b3b0-fda747a4e65d
Raw SQL
SELECT
"label_links".*
FROM
"label_links"
WHERE
"label_links"."target_type" = 'AbuseReport'
AND "label_links"."target_id" IN (124381, 124377, 124258, 124252, 124679, 124678, 124254, 124257, 124866, 124384, 124674, 124672, 124234, 124924, 124829, 124684, 125701, 125222, 124895, 124991);
Label
Query 2: EXPLAIN: https://console.postgres.ai/shared/f4480aba-67c4-4020-b3f0-4b56833f856e
Raw SQL
# Here, the sub-query (SELECT id FROM labels WHERE type = 'Admin::AbuseReportLabel' LIMIT 100) is actually a list of IDs taken from the LabelLink query above so the query should perform faster during actual usage.
SELECT
"labels".*
FROM
"labels"
WHERE
"labels"."id" IN (
SELECT
id
FROM
labels
WHERE
type = 'Admin::AbuseReportLabel'
LIMIT 100)
ORDER BY
"labels"."title" ASC;
Screenshots or screen recordings
How to set up and validate locally
- Enable the feature flag
$ rails console > Feature.enable(:abuse_report_labels)
- Go to localhost:3000/admin/abuse_reports, select a report and assign labels to it. You can create some via the dropdown if there are no existing labels
- Go back to localhost:3000/admin/abuse_reports and validate that the labels you assigned are shown for the report
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.