fix(subscribe): improve logging and update query logic for server filtering
This commit is contained in:
parent
77f55f8708
commit
ddf740600f
@ -117,9 +117,12 @@ func (l *SubscribeLogic) getServers(userSub *user.Subscribe) ([]*server.Server,
|
||||
serverIds := tool.StringToInt64Slice(subDetails.Server)
|
||||
groupIds := tool.StringToInt64Slice(subDetails.ServerGroup)
|
||||
|
||||
logger.Debugf("[Generate Subscribe]serverIds: %v, groupIds: %v", serverIds, groupIds)
|
||||
l.Debugf("[Generate Subscribe]serverIds: %v, groupIds: %v", serverIds, groupIds)
|
||||
|
||||
servers, err := l.svc.ServerModel.FindServerDetailByGroupIdsAndIds(l.ctx.Request.Context(), groupIds, serverIds)
|
||||
|
||||
l.Debugf("[Query Subscribe]found servers: %v", len(servers))
|
||||
|
||||
if err != nil {
|
||||
l.Errorw("[Generate Subscribe]find server details error: %v", logger.Field("error", err.Error()))
|
||||
return nil, errors.Wrapf(xerr.NewErrCode(xerr.DatabaseQueryError), "find server details error: %v", err.Error())
|
||||
|
||||
@ -117,13 +117,16 @@ func (m *customServerModel) FindServerDetailByGroupIdsAndIds(ctx context.Context
|
||||
err := m.QueryNoCacheCtx(ctx, &list, func(conn *gorm.DB, v interface{}) error {
|
||||
conn = conn.
|
||||
Model(&Server{}).
|
||||
Where("enable = ?", true)
|
||||
if len(groupId) > 0 {
|
||||
conn = conn.Or("group_id IN ?", groupId)
|
||||
}
|
||||
if len(ids) > 0 {
|
||||
conn = conn.Where("id IN ?", ids)
|
||||
Where("`enable` = ?", true)
|
||||
if len(groupId) > 0 && len(ids) > 0 {
|
||||
// OR is used to connect group_id and id conditions
|
||||
conn = conn.Where("(`group_id` IN ? OR `id` IN ?)", groupId, ids)
|
||||
} else if len(groupId) > 0 {
|
||||
conn = conn.Where("`group_id` IN ?", groupId)
|
||||
} else if len(ids) > 0 {
|
||||
conn = conn.Where("`id` IN ?", ids)
|
||||
}
|
||||
|
||||
return conn.Order("sort ASC").Find(v).Error
|
||||
})
|
||||
return list, err
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user