FEATURE: Include muted users count within the ignored users report (#7230)
This commit is contained in:
parent
c18a6069c2
commit
605530a77f
|
@ -1591,31 +1591,59 @@ class Report
|
|||
:ignores_count,
|
||||
],
|
||||
title: I18n.t("reports.top_ignored_users.labels.ignores_count")
|
||||
},
|
||||
{
|
||||
type: :number,
|
||||
properties: [
|
||||
:mutes_count,
|
||||
],
|
||||
title: I18n.t("reports.top_ignored_users.labels.mutes_count")
|
||||
}
|
||||
]
|
||||
|
||||
report.data = []
|
||||
|
||||
sql = <<~SQL
|
||||
SELECT
|
||||
u.id AS user_id,
|
||||
u.username,
|
||||
u.uploaded_avatar_id,
|
||||
COUNT(*) AS ignores_count
|
||||
FROM users AS u
|
||||
INNER JOIN ignored_users AS ig ON ig.ignored_user_id = u.id
|
||||
WHERE ig.created_at >= '#{report.start_date}' AND ig.created_at <= '#{report.end_date}'
|
||||
GROUP BY u.id
|
||||
ORDER BY COUNT(*) DESC
|
||||
LIMIT #{report.limit || 250}
|
||||
WITH ignored_users AS (
|
||||
SELECT
|
||||
ignored_user_id as user_id,
|
||||
COUNT(*) AS ignores_count
|
||||
FROM ignored_users
|
||||
WHERE created_at >= '#{report.start_date}' AND created_at <= '#{report.end_date}'
|
||||
GROUP BY ignored_user_id
|
||||
ORDER BY COUNT(*) DESC
|
||||
LIMIT :limit
|
||||
),
|
||||
muted_users AS (
|
||||
SELECT
|
||||
muted_user_id as user_id,
|
||||
COUNT(*) AS mutes_count
|
||||
FROM muted_users
|
||||
WHERE created_at >= '#{report.start_date}' AND created_at <= '#{report.end_date}'
|
||||
GROUP BY muted_user_id
|
||||
ORDER BY COUNT(*) DESC
|
||||
LIMIT :limit
|
||||
)
|
||||
|
||||
SELECT u.id as user_id,
|
||||
u.username as username,
|
||||
u.uploaded_avatar_id as uploaded_avatar_id,
|
||||
ig.ignores_count as ignores_count,
|
||||
COALESCE(mu.mutes_count, 0) as mutes_count,
|
||||
ig.ignores_count + COALESCE(mu.mutes_count, 0) as total
|
||||
FROM users as u
|
||||
JOIN ignored_users as ig ON ig.user_id = u.id
|
||||
LEFT OUTER JOIN muted_users as mu ON mu.user_id = u.id
|
||||
ORDER BY total DESC
|
||||
SQL
|
||||
|
||||
DB.query(sql).each do |row|
|
||||
DB.query(sql, limit: report.limit || 250).each do |row|
|
||||
report.data << {
|
||||
ignored_user_id: row.user_id,
|
||||
ignored_username: row.username,
|
||||
ignored_user_avatar_template: User.avatar_template(row.username, row.uploaded_avatar_id),
|
||||
ignores_count: row.ignores_count,
|
||||
mutes_count: row.mutes_count,
|
||||
}
|
||||
end
|
||||
end
|
||||
|
|
|
@ -1234,6 +1234,7 @@ en:
|
|||
labels:
|
||||
ignored_user: Ignored User
|
||||
ignores_count: Ignores count
|
||||
mutes_count: Mutes count
|
||||
description: "List top ignored users."
|
||||
|
||||
dashboard:
|
||||
|
|
|
@ -0,0 +1,3 @@
|
|||
Fabricator(:muted_user) do
|
||||
user
|
||||
end
|
|
@ -1108,15 +1108,29 @@ describe Report do
|
|||
|
||||
it "works" do
|
||||
expect(report.data.length).to eq(2)
|
||||
expect_row_to_be_equal(report.data[0], john)
|
||||
expect_row_to_be_equal(report.data[1], matt)
|
||||
expect_row_to_be_equal(report.data[0], john, 1, 0)
|
||||
expect_row_to_be_equal(report.data[1], matt, 1, 0)
|
||||
end
|
||||
|
||||
def expect_row_to_be_equal(row, user)
|
||||
def expect_row_to_be_equal(row, user, ignores, mutes)
|
||||
expect(row[:ignored_user_id]).to eq(user.id)
|
||||
expect(row[:ignored_username]).to eq(user.username)
|
||||
expect(row[:ignored_user_avatar_template]).to eq(User.avatar_template(user.username, user.uploaded_avatar_id))
|
||||
expect(row[:ignores_count]).to eq(1)
|
||||
expect(row[:ignores_count]).to eq(ignores)
|
||||
expect(row[:mutes_count]).to eq(mutes)
|
||||
end
|
||||
|
||||
context "when muted users exist" do
|
||||
before do
|
||||
Fabricate(:muted_user, user: tarek, muted_user: john)
|
||||
Fabricate(:muted_user, user: tarek, muted_user: matt)
|
||||
end
|
||||
|
||||
it "works" do
|
||||
expect(report.data.length).to eq(2)
|
||||
expect_row_to_be_equal(report.data[0], john, 1, 1)
|
||||
expect_row_to_be_equal(report.data[1], matt, 1, 1)
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
|
|
Loading…
Reference in New Issue