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
This commit is contained in:
Sofia Papagiannaki 2019-11-27 19:57:08 +02:00 committed by Marcus Efraimsson
parent 5cfc681175
commit 02d7d00560

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