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,18 +5,22 @@ module EE ...@@ -5,18 +5,22 @@ 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'
WHEN 40 THEN 'master' WHEN 40 THEN 'master'
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 #{table_name} FROM (
SELECT user_id, max(access_level) AS access_level
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