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
custom-unit-formats
Sofia Papagiannaki 6 years ago committed by Marcus Efraimsson
parent 5cfc681175
commit 02d7d00560
  1. 4
      pkg/services/sqlstore/stats.go

@ -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

Loading…
Cancel
Save