Commit 02d7d005 by Sofia Papagiannaki Committed by Marcus Efraimsson

SQLStore: Rewrite system statistics query to count users once (#20711)

Fix system statistics query to count only once users that are 
part of several organisations.

Fixes #20681
parent 5cfc6811
...@@ -95,12 +95,12 @@ func GetSystemStats(query *m.GetSystemStatsQuery) error { ...@@ -95,12 +95,12 @@ func GetSystemStats(query *m.GetSystemStatsQuery) error {
func roleCounterSQL(role, alias string) string { func roleCounterSQL(role, alias string) string {
return ` return `
( (
SELECT COUNT(*) SELECT COUNT(DISTINCT u.id)
FROM ` + dialect.Quote("user") + ` as u, org_user FROM ` + dialect.Quote("user") + ` as u, org_user
WHERE ( org_user.user_id=u.id AND org_user.role='` + role + `' ) WHERE ( org_user.user_id=u.id AND org_user.role='` + role + `' )
) as ` + alias + `, ) as ` + alias + `,
( (
SELECT COUNT(*) SELECT COUNT(DISTINCT u.id)
FROM ` + dialect.Quote("user") + ` as u, org_user FROM ` + dialect.Quote("user") + ` as u, org_user
WHERE u.last_seen_at>? AND ( org_user.user_id=u.id AND org_user.role='` + role + `' ) WHERE u.last_seen_at>? AND ( org_user.user_id=u.id AND org_user.role='` + role + `' )
) as active_` + alias ) as active_` + alias
......
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