admin-analytics: optimize user management data layer
Created by: erzhtor
It seems that because user management SQL queries use join
large event_logs and users tables to create a full in-memory table, the GQL API response is slow and even fails with a time-out exception.
This PR:
- Extracts query logic into separate
internal/users/stats.go
file - Adds
aggregated_user_statistics
table which is updated/seeded every 12 hours - Adds
SiteUser.displayName
GQL field
Test plan
sg start
- http://localhost:3080/api/console
query UsersManagementUsersList {
site {
users(query: null, lastActivePeriod: THIS_MONTH) {
totalCount
nodes(first: 25, orderBy: EVENTS_COUNT, descending: true) {
id
username
email
siteAdmin
eventsCount
createdAt
lastActiveAt
deletedAt
}
}
}
}