Skip to content

Aggregate multiple abuse reports by the user & category (list-view)

Hinam Mehra requested to merge anti-abuse/180-aggregate-abuse-reports into master

What does this MR do and why?

Frontend:

  • Adds a new sorting option, Number of Reports for open reports. This is the default sorting option for open reports.
  • Since, closed reports are not aggregated, their default sorting option is still Created date
  • Fixes a minor bug in the filter bar, so that Status = X always appears first.

Backend:

  • Updates AbuseReportsFinder so it aggregates and sorts open reports. Closed reports don't get aggregated. Since, we get a lot of abuse reports, aggregating closed reports would have been not as performative.
  • Adds count to the AbuseReportEntity with a default = 1.

Database

No changes have been made to the tables, but here are the query plans for the new query

Insert Data
# status = closed & category = 1 (10K)
exec 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(4038079, 4048079) as user_id;
 
# status = open & category = 1 (10K)
exec INSERT INTO "abuse_reports" ("reporter_id", "user_id", "message", "created_at", "updated_at", "message_html", "cached_markdown_version", "category", "status") SELECT 9670031, user_id, 'spammer', '2023-02-07 09:51:12.678028', '2023-02-07 09:51:12.678028', 'spammer', 2097152, 1, 2 FROM generate_series(4038079, 4048079) as user_id;

# status = open & category = 1 & user_id = 9670032 (1K)
exec INSERT INTO "abuse_reports" ("user_id", "reporter_id", "message", "created_at", "updated_at", "message_html", "cached_markdown_version") SELECT 9670032, reporter_id, 'spammer', '2023-02-07 09:51:12.678028', '2023-02-07 09:51:12.678028', 'spammer', 2097152 FROM generate_series(4038079, 4039079) as reporter_id;

Screenshots or screen recordings

Before After
before after

How to set up and validate locally

  1. In rails console
> Feature.enable(:abuse_reports_list)

# seed data
> AbuseReport.delete_all

# create 10 different reports for the same user & category
> User.limit(10).order_id_asc.pluck("id").each { |i| AbuseReport.create(reporter_id: i, user_id: User.last.id, status: "open", category: "spam", message: "test") }

# create another 10 for the same user but different category
> User.limit(10).order_id_asc.pluck("id").each { |i| AbuseReport.create(reporter_id: i, user_id: User.last.id, status: "open", category: "offensive", message: "test") }

# create 20 more for different users
> User.limit(20).order_id_asc.pluck("id").each { |i| AbuseReport.create(reporter_id: User.first.id, user_id: i, status: "open", category: "crypto", message: "test") }
  1. Log-in as admin and navigate to /admin/abuse_reports

MR acceptance checklist

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

Edited by Hinam Mehra

Merge request reports