ListDistinctUsers 返回最近 since 时间段内出现过的 distinct username(截取 @ 前缀,去重)。
(since time.Time)
| 110 | |
| 111 | // ListDistinctUsers 返回最近 since 时间段内出现过的 distinct username(截取 @ 前缀,去重)。 |
| 112 | func (s *AccessLogStore) ListDistinctUsers(since time.Time) ([]string, error) { |
| 113 | ctx := context.Background() |
| 114 | rows, err := s.db.Query(ctx, |
| 115 | `SELECT DISTINCT SPLIT_PART(username, '@', 1) FROM access_logs WHERE created_at >= $1 ORDER BY 1`, |
| 116 | since, |
| 117 | ) |
| 118 | if err != nil { |
| 119 | return nil, fmt.Errorf("list distinct users: %w", err) |
| 120 | } |
| 121 | defer rows.Close() |
| 122 | var out []string |
| 123 | for rows.Next() { |
| 124 | var u string |
| 125 | if err := rows.Scan(&u); err != nil { |
| 126 | return nil, err |
| 127 | } |
| 128 | out = append(out, u) |
| 129 | } |
| 130 | return out, rows.Err() |
| 131 | } |
| 132 | |
| 133 | func (s *AccessLogStore) ListUserAnalysis(since, until time.Time) ([]accesslogs.UserAnalysis, error) { |
| 134 | ctx := context.Background() |