From 9abe6c52b1e91677ed6af1d0e1be1683630688ca Mon Sep 17 00:00:00 2001 From: hujiebin Date: Thu, 31 Aug 2023 17:24:52 +0800 Subject: [PATCH] =?UTF-8?q?GetGroupVisitorsV2=EF=BC=9A=E7=94=A8=E6=89=B9?= =?UTF-8?q?=E9=87=8F=E7=9C=8B=E7=9C=8B?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- domain/model/user_m/user.go | 19 +++++++++++++++++-- route/group_r/group_list.go | 2 +- 2 files changed, 18 insertions(+), 3 deletions(-) diff --git a/domain/model/user_m/user.go b/domain/model/user_m/user.go index a51520e..bc83bab 100644 --- a/domain/model/user_m/user.go +++ b/domain/model/user_m/user.go @@ -155,9 +155,24 @@ func GetUserExternalIds(model *domain.Model, userIds []mysql.ID) ([]string, map[ return res, m, c } var users []User - if err := model.DB().Model(User{}).Where("id in (?)", userIds).Select("id,external_id").Find(&users).Error; err != nil { - model.Log.Errorf("GetUserExternalIds fail:%v", err) + total := len(userIds) + const NUM = 500 + start, end := 0, NUM + for start < total { + if end > total { + end = total + } + var tmp []User + tmpUserId := userIds[start:end] + if err := model.DB().Model(User{}).Where("id in (?)", tmpUserId).Select("id,external_id,code").Find(&tmp).Error; err != nil { + model.Log.Errorf("GetUserExternalIds fail:%v", err) + } else if len(tmp) > 0 { + users = append(users, tmp...) + } + start += NUM + end += NUM } + for _, user := range users { res = append(res, user.ExternalId) m[user.ID] = user.ExternalId diff --git a/route/group_r/group_list.go b/route/group_r/group_list.go index a4d6585..ca16770 100644 --- a/route/group_r/group_list.go +++ b/route/group_r/group_list.go @@ -1039,7 +1039,7 @@ func GetGroupVisitorsV2(c *gin.Context) (*mycontext.MyContext, error) { beginPos := pageSize * (pageIndex - 1) if uint(beginPos) < result.Total { // 取在线状态 - extIds, userExtIdMap, userCodeMap := user_c.GetUserExternalIds(model, userIds) + extIds, userExtIdMap, userCodeMap := user_m.GetUserExternalIds(model, userIds) statusMap, err := tim_m.GetOnlineStatus(model, extIds) if err != nil { return myContext, err -- 2.22.0