Commit e5d3d06a authored by Dmitriy Zaporozhets's avatar Dmitriy Zaporozhets

Improve sql query to remove duplicates for roles stats

Signed-off-by: default avatarDmitriy Zaporozhets <dmitriy.zaporozhets@gmail.com>
parent 316c9044
...@@ -5,7 +5,7 @@ module EE ...@@ -5,7 +5,7 @@ module EE
module ClassMethods module ClassMethods
def roles_stats def roles_stats
connection.execute <<-EOF.strip_heredoc connection.execute <<-EOF.strip_heredoc
SELECT CASE max(access_level) SELECT CASE access_level
WHEN 10 THEN 'guest' WHEN 10 THEN 'guest'
WHEN 20 THEN 'reporter' WHEN 20 THEN 'reporter'
WHEN 30 THEN 'developer' WHEN 30 THEN 'developer'
...@@ -13,10 +13,14 @@ module EE ...@@ -13,10 +13,14 @@ module EE
WHEN 50 THEN 'owner' WHEN 50 THEN 'owner'
ELSE 'unknown' END ELSE 'unknown' END
AS kind, AS kind,
count(DISTINCT user_id) AS amount count(*) AS amount
FROM (
SELECT user_id, max(access_level) AS access_level
FROM #{table_name} FROM #{table_name}
GROUP BY user_id
) access_per_user
GROUP BY access_level GROUP BY access_level
ORDER BY amount DESC; ORDER BY access_level ASC;
EOF EOF
end end
end end
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment