| 71 | } |
| 72 | |
| 73 | func (s *Store) IncrementUsageSummary(ctx context.Context, userID, bucketDate, direction string) error { |
| 74 | inbound, outbound := 0, 0 |
| 75 | if direction == "inbound" { |
| 76 | inbound = 1 |
| 77 | } else { |
| 78 | outbound = 1 |
| 79 | } |
| 80 | _, err := s.pool.Exec(ctx, |
| 81 | `INSERT INTO usage_summaries (user_id, bucket_date, inbound_count, outbound_count, total_count) |
| 82 | VALUES ($1, $2, $3, $4, $5) |
| 83 | ON CONFLICT (user_id, bucket_date) DO UPDATE SET |
| 84 | inbound_count = usage_summaries.inbound_count + $3, |
| 85 | outbound_count = usage_summaries.outbound_count + $4, |
| 86 | total_count = usage_summaries.total_count + $5`, |
| 87 | userID, bucketDate, inbound, outbound, inbound+outbound, |
| 88 | ) |
| 89 | return err |
| 90 | } |
| 91 | |
| 92 | // GetAccountClass returns the account class for a user. A missing user (no row) |
| 93 | // resolves to ClassStandard so the metering gate fails toward metering — a |