GetAccountClass returns the account class for a user. A missing user (no row) resolves to ClassStandard so the metering gate fails toward metering — a real customer must never be silently exempted from billing because of a transient lookup miss. The PK lookup on users is cheap; account class is read
(ctx context.Context, userID string)
| 95 | // transient lookup miss. The PK lookup on users is cheap; account class is read |
| 96 | // once per metered message. |
| 97 | func (s *Store) GetAccountClass(ctx context.Context, userID string) (AccountClass, error) { |
| 98 | var class string |
| 99 | err := s.pool.QueryRow(ctx, |
| 100 | `SELECT account_class FROM users WHERE id = $1`, userID, |
| 101 | ).Scan(&class) |
| 102 | if err != nil { |
| 103 | if errors.Is(err, pgx.ErrNoRows) { |
| 104 | return ClassStandard, nil |
| 105 | } |
| 106 | return ClassStandard, err |
| 107 | } |
| 108 | return AccountClass(class), nil |
| 109 | } |
| 110 | |
| 111 | func (s *Store) CountAgentsByUser(ctx context.Context, userID string) (int, error) { |
| 112 | var count int |
no test coverage detected