fix(api): 修正用户列表查询逻辑以避免重复

- 将查询语句从 activity 表改为 user 表,优化数据来源
- 修改排序字段由 user_id 改为 id,保持一致性
- 移除代码中对用户 ID 的去重逻辑,简化处理流程
- 保持空用户名用用户 ID 字符串替代的逻辑不变
This commit is contained in:
zhouyonggao 2025-12-19 01:00:51 +08:00
parent c27cf278dd
commit 43d67073c9
1 changed files with 2 additions and 8 deletions

View File

@ -32,9 +32,9 @@ func (a *YMTUsersAPI) list(w http.ResponseWriter, r *http.Request) {
limit = n limit = n
} }
} }
sql1 := "SELECT DISTINCT user_id, COALESCE(user_name, '') AS name FROM activity WHERE user_id IS NOT NULL" sql1 := "SELECT id, name FROM user WHERE id IS NOT NULL"
args := []interface{}{} args := []interface{}{}
sql1 += " ORDER BY user_id ASC LIMIT ?" sql1 += " ORDER BY id ASC LIMIT ?"
args = append(args, limit) args = append(args, limit)
rows, err := a.ymt.Query(sql1, args...) rows, err := a.ymt.Query(sql1, args...)
if err != nil { if err != nil {
@ -54,12 +54,6 @@ func (a *YMTUsersAPI) list(w http.ResponseWriter, r *http.Request) {
if !id.Valid { if !id.Valid {
continue continue
} }
if _, ok := used[id.Int64]; ok {
// 根据 ID 去重
continue
}
used[id.Int64] = struct{}{}
n := strings.TrimSpace(name.String) n := strings.TrimSpace(name.String)
if n == "" { if n == "" {
n = strconv.FormatInt(id.Int64, 10) n = strconv.FormatInt(id.Int64, 10)