modified internal/db/oauth_store.go +6 -0
| @@ -76,6 +76,12 @@ func (s *OAuthStore) ListSessionsForDID(ctx context.Context, did string) ([]stri |
| 76 | 76 | return ids, rows.Err() |
| 77 | 77 | } |
| 78 | 78 | |
| 79 | +func (s *OAuthStore) CountActiveUsers(ctx context.Context) (int, error) { |
| 80 | + var count int |
| 81 | + err := s.db.QueryRowContext(ctx, `SELECT COUNT(DISTINCT account_did) FROM oauth_sessions`).Scan(&count) |
| 82 | + return count, err |
| 83 | +} |
| 84 | + |
| 79 | 85 | func (s *OAuthStore) GetAuthRequestInfo(ctx context.Context, state string) (*oauth.AuthRequestData, error) { |
| 80 | 86 | var data []byte |
| 81 | 87 | err := s.db.QueryRowContext(ctx, ` |
| @@ -76,6 +76,12 @@ func (s *OAuthStore) ListSessionsForDID(ctx context.Context, did string) ([]stri |
| 76 | return ids, rows.Err() | 76 | return ids, rows.Err() |
| 77 | } | 77 | } |
| 78 | | 78 | |
| | 79 | +func (s *OAuthStore) CountActiveUsers(ctx context.Context) (int, error) { |
| | 80 | + var count int |
| | 81 | + err := s.db.QueryRowContext(ctx, `SELECT COUNT(DISTINCT account_did) FROM oauth_sessions`).Scan(&count) |
| | 82 | + return count, err |
| | 83 | +} |
| | 84 | + |
| 79 | func (s *OAuthStore) GetAuthRequestInfo(ctx context.Context, state string) (*oauth.AuthRequestData, error) { | 85 | func (s *OAuthStore) GetAuthRequestInfo(ctx context.Context, state string) (*oauth.AuthRequestData, error) { |
| 80 | var data []byte | 86 | var data []byte |
| 81 | err := s.db.QueryRowContext(ctx, ` | 87 | err := s.db.QueryRowContext(ctx, ` |
modified internal/server/server.go +4 -0
| @@ -470,6 +470,10 @@ func (s *Server) BackfillFromCollectionDir(ctx context.Context, collectionDirURL |
| 470 | 470 | } |
| 471 | 471 | |
| 472 | 472 | func (s *Server) runSyncAll(ctx context.Context) { |
| 473 | + if n, err := s.oauthStore.CountActiveUsers(ctx); err == nil { |
| 474 | + metrics.ActiveUsers.Set(float64(n)) |
| 475 | + } |
| 476 | + |
| 473 | 477 | users, err := s.dbs.Users.ListUsers(ctx) |
| 474 | 478 | if err != nil { |
| 475 | 479 | s.logger.Error("failed to list users for sync", "error", err) |
| @@ -470,6 +470,10 @@ func (s *Server) BackfillFromCollectionDir(ctx context.Context, collectionDirURL |
| 470 | } | 470 | } |
| 471 | | 471 | |
| 472 | func (s *Server) runSyncAll(ctx context.Context) { | 472 | func (s *Server) runSyncAll(ctx context.Context) { |
| | 473 | + if n, err := s.oauthStore.CountActiveUsers(ctx); err == nil { |
| | 474 | + metrics.ActiveUsers.Set(float64(n)) |
| | 475 | + } |
| | 476 | + |
| 473 | users, err := s.dbs.Users.ListUsers(ctx) | 477 | users, err := s.dbs.Users.ListUsers(ctx) |
| 474 | if err != nil { | 478 | if err != nil { |
| 475 | s.logger.Error("failed to list users for sync", "error", err) | 479 | s.logger.Error("failed to list users for sync", "error", err) |