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

(cherry picked from commit 02d7d00560)
This commit is contained in:
Sofia Papagiannaki
2019-11-28 08:43:49 +01:00
committed by Hugo Häggmark
parent e3db87d27a
commit 8e7f6cd454
+2 -2
View File
@@ -95,12 +95,12 @@ func GetSystemStats(query *m.GetSystemStatsQuery) error {
func roleCounterSQL(role, alias string) string {
return `
(
SELECT COUNT(*)
SELECT COUNT(DISTINCT u.id)
FROM ` + dialect.Quote("user") + ` as u, org_user
WHERE ( org_user.user_id=u.id AND org_user.role='` + role + `' )
) as ` + alias + `,
(
SELECT COUNT(*)
SELECT COUNT(DISTINCT u.id)
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 + `' )
) as active_` + alias