Add sort by created_at and updated_at to abuse reports list
What does this MR do and why?
This MR resolves Implement sorting by updated_at and created_at as part of https://gitlab.com/gitlab-org/modelops/anti-abuse/team-tasks/-/issues/157+.
It updates the abuse reports list to allow sorting displayed reports by created_at_desc
(default), created_at_asc
, updated_at_desc
, and updated_at_asc
.
Database changes
AbuseReport.order_created_desc and AbuseReport.order_created_desc scopes
These scopes are provided by Sortable concern and are covered by the newly added index on (status, created_at)
.
Raw SQL
SELECT
"abuse_reports".*
FROM
"abuse_reports"
WHERE
"abuse_reports"."status" = 1
ORDER BY
"abuse_reports"."created_at" DESC
LIMIT 20 OFFSET 4980
Query plan
Generated after inserting 10k abuse report records.
INSERT statements
INSERT INTO "abuse_reports" ("reporter_id", "user_id", "message", "created_at", "updated_at", "message_html", "cached_markdown_version") SELECT 9670031, user_id, 'spammer', '2023-02-07 09:51:12.678028', '2023-02-07 09:51:12.678028', 'spammer', 2097152 FROM generate_series(4018077, 4023077) as user_id;
INSERT INTO "abuse_reports" ("reporter_id", "user_id", "message", "created_at", "updated_at", "message_html", "cached_markdown_version") SELECT 9670031, user_id, 'spammer', '2023-02-07 09:51:12.678028', '2023-02-07 09:51:12.678028', 'spammer', 2097152 FROM generate_series(4023078, 4028078) as user_id;
https://console.postgres.ai/shared/bb7effef-92a1-42cf-a4cc-5f9f75e3b00c
AbuseReport.order_created_desc and AbuseReport.order_created_desc scopes
These scopes are provided by Sortable concern and are covered by the newly added index on (status, updated_at)
.
Raw SQL
SELECT
"abuse_reports".*
FROM
"abuse_reports"
WHERE
"abuse_reports"."status" = 1
ORDER BY
"abuse_reports"."updated_at" DESC
LIMIT 20 OFFSET 4980
Query plan
Generated after inserting 10k abuse report records.
INSERT statements
INSERT INTO "abuse_reports" ("reporter_id", "user_id", "message", "created_at", "updated_at", "message_html", "cached_markdown_version") SELECT 9670031, user_id, 'spammer', '2023-02-07 09:51:12.678028', '2023-02-07 09:51:12.678028', 'spammer', 2097152 FROM generate_series(4018077, 4023077) as user_id;
INSERT INTO "abuse_reports" ("reporter_id", "user_id", "message", "created_at", "updated_at", "message_html", "cached_markdown_version") SELECT 9670031, user_id, 'spammer', '2023-02-07 09:51:12.678028', '2023-02-07 09:51:12.678028', 'spammer', 2097152 FROM generate_series(4023078, 4028078) as user_id;
https://console.postgres.ai/shared/1057bc73-ca86-4b6a-845a-3a598a54ff86
Screenshots or screen recordings
Screen_Recording_2023-03-10_at_2.54.39_PM
page
query param is removed when sorting changes
Screen_Recording_2023-03-10_at_2.56.24_PM
sort
query param is retained when filter changes
Screen_Recording_2023-03-10_at_2.57.56_PM
How to set up and validate locally
-
Enable the feature flag
$ rails console > Feature.enable(:abuse_reports_list)
-
Login with an admin account
-
Go to the Abuse Reports page (http://localhost:3000/admin/abuse_reports)
-
Validate that the list can be sorted by
Created at
in descending and ascending order -
Validate that the list can be sorted by
Updated at
in descending and ascending order
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.