Commit 9abe6c52 authored by hujiebin's avatar hujiebin

GetGroupVisitorsV2:用批量看看

parent 82b87ac2
...@@ -155,9 +155,24 @@ func GetUserExternalIds(model *domain.Model, userIds []mysql.ID) ([]string, map[ ...@@ -155,9 +155,24 @@ func GetUserExternalIds(model *domain.Model, userIds []mysql.ID) ([]string, map[
return res, m, c return res, m, c
} }
var users []User var users []User
if err := model.DB().Model(User{}).Where("id in (?)", userIds).Select("id,external_id").Find(&users).Error; err != nil { total := len(userIds)
model.Log.Errorf("GetUserExternalIds fail:%v", err) 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 { for _, user := range users {
res = append(res, user.ExternalId) res = append(res, user.ExternalId)
m[user.ID] = user.ExternalId m[user.ID] = user.ExternalId
......
...@@ -1039,7 +1039,7 @@ func GetGroupVisitorsV2(c *gin.Context) (*mycontext.MyContext, error) { ...@@ -1039,7 +1039,7 @@ func GetGroupVisitorsV2(c *gin.Context) (*mycontext.MyContext, error) {
beginPos := pageSize * (pageIndex - 1) beginPos := pageSize * (pageIndex - 1)
if uint(beginPos) < result.Total { 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) statusMap, err := tim_m.GetOnlineStatus(model, extIds)
if err != nil { if err != nil {
return myContext, err return myContext, err
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment