mirror of
https://gitee.com/wanwujie/sub2api
synced 2026-04-12 02:54:44 +08:00
Revert "fix: 并发/排队面板支持 platform/group 过滤"
This reverts commit 86e600aa52.
This commit is contained in:
@@ -65,10 +65,6 @@ func (h *OpsHandler) GetConcurrencyStats(c *gin.Context) {
|
||||
|
||||
// GetUserConcurrencyStats returns real-time concurrency usage for all active users.
|
||||
// GET /api/v1/admin/ops/user-concurrency
|
||||
//
|
||||
// Query params:
|
||||
// - platform: optional, filter users by allowed platform
|
||||
// - group_id: optional, filter users by allowed group
|
||||
func (h *OpsHandler) GetUserConcurrencyStats(c *gin.Context) {
|
||||
if h.opsService == nil {
|
||||
response.Error(c, http.StatusServiceUnavailable, "Ops service not available")
|
||||
@@ -88,18 +84,7 @@ func (h *OpsHandler) GetUserConcurrencyStats(c *gin.Context) {
|
||||
return
|
||||
}
|
||||
|
||||
platformFilter := strings.TrimSpace(c.Query("platform"))
|
||||
var groupID *int64
|
||||
if v := strings.TrimSpace(c.Query("group_id")); v != "" {
|
||||
id, err := strconv.ParseInt(v, 10, 64)
|
||||
if err != nil || id <= 0 {
|
||||
response.BadRequest(c, "Invalid group_id")
|
||||
return
|
||||
}
|
||||
groupID = &id
|
||||
}
|
||||
|
||||
users, collectedAt, err := h.opsService.GetUserConcurrencyStats(c.Request.Context(), platformFilter, groupID)
|
||||
users, collectedAt, err := h.opsService.GetUserConcurrencyStats(c.Request.Context())
|
||||
if err != nil {
|
||||
response.ErrorFrom(c, err)
|
||||
return
|
||||
|
||||
@@ -344,16 +344,8 @@ func (s *OpsService) getUsersLoadMapBestEffort(ctx context.Context, users []User
|
||||
return out
|
||||
}
|
||||
|
||||
// GetUserConcurrencyStats returns real-time concurrency usage for active users.
|
||||
//
|
||||
// Optional filters:
|
||||
// - platformFilter: only include users who have access to groups belonging to that platform
|
||||
// - groupIDFilter: only include users who have access to that specific group
|
||||
func (s *OpsService) GetUserConcurrencyStats(
|
||||
ctx context.Context,
|
||||
platformFilter string,
|
||||
groupIDFilter *int64,
|
||||
) (map[int64]*UserConcurrencyInfo, *time.Time, error) {
|
||||
// GetUserConcurrencyStats returns real-time concurrency usage for all active users.
|
||||
func (s *OpsService) GetUserConcurrencyStats(ctx context.Context) (map[int64]*UserConcurrencyInfo, *time.Time, error) {
|
||||
if err := s.RequireMonitoringEnabled(ctx); err != nil {
|
||||
return nil, nil, err
|
||||
}
|
||||
@@ -363,15 +355,6 @@ func (s *OpsService) GetUserConcurrencyStats(
|
||||
return nil, nil, err
|
||||
}
|
||||
|
||||
// Build a set of allowed group IDs when filtering is requested.
|
||||
var allowedGroupIDs map[int64]struct{}
|
||||
if platformFilter != "" || (groupIDFilter != nil && *groupIDFilter > 0) {
|
||||
allowedGroupIDs, err = s.buildAllowedGroupIDsForFilter(ctx, platformFilter, groupIDFilter)
|
||||
if err != nil {
|
||||
return nil, nil, err
|
||||
}
|
||||
}
|
||||
|
||||
collectedAt := time.Now()
|
||||
loadMap := s.getUsersLoadMapBestEffort(ctx, users)
|
||||
|
||||
@@ -382,12 +365,6 @@ func (s *OpsService) GetUserConcurrencyStats(
|
||||
continue
|
||||
}
|
||||
|
||||
// Apply group/platform filter: skip users whose AllowedGroups
|
||||
// have no intersection with the matching group IDs.
|
||||
if allowedGroupIDs != nil && !userMatchesGroupFilter(u.AllowedGroups, allowedGroupIDs) {
|
||||
continue
|
||||
}
|
||||
|
||||
load := loadMap[u.ID]
|
||||
currentInUse := int64(0)
|
||||
waiting := int64(0)
|
||||
@@ -417,46 +394,3 @@ func (s *OpsService) GetUserConcurrencyStats(
|
||||
|
||||
return result, &collectedAt, nil
|
||||
}
|
||||
|
||||
// buildAllowedGroupIDsForFilter returns the set of group IDs that match the given
|
||||
// platform and/or group ID filter. It reuses listAllAccountsForOps (which already
|
||||
// supports platform filtering at the DB level) to collect group IDs from accounts.
|
||||
func (s *OpsService) buildAllowedGroupIDsForFilter(ctx context.Context, platformFilter string, groupIDFilter *int64) (map[int64]struct{}, error) {
|
||||
// Fast path: only group ID filter, no platform filter needed.
|
||||
if platformFilter == "" && groupIDFilter != nil && *groupIDFilter > 0 {
|
||||
return map[int64]struct{}{*groupIDFilter: {}}, nil
|
||||
}
|
||||
|
||||
// Use the same account-based approach as GetConcurrencyStats to collect group IDs.
|
||||
accounts, err := s.listAllAccountsForOps(ctx, platformFilter)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
|
||||
groupIDs := make(map[int64]struct{})
|
||||
for _, acc := range accounts {
|
||||
for _, grp := range acc.Groups {
|
||||
if grp == nil || grp.ID <= 0 {
|
||||
continue
|
||||
}
|
||||
// If groupIDFilter is set, only include that specific group.
|
||||
if groupIDFilter != nil && *groupIDFilter > 0 && grp.ID != *groupIDFilter {
|
||||
continue
|
||||
}
|
||||
groupIDs[grp.ID] = struct{}{}
|
||||
}
|
||||
}
|
||||
|
||||
return groupIDs, nil
|
||||
}
|
||||
|
||||
// userMatchesGroupFilter returns true if the user's AllowedGroups contains
|
||||
// at least one group ID in the allowed set.
|
||||
func userMatchesGroupFilter(userGroups []int64, allowedGroupIDs map[int64]struct{}) bool {
|
||||
for _, gid := range userGroups {
|
||||
if _, ok := allowedGroupIDs[gid]; ok {
|
||||
return true
|
||||
}
|
||||
}
|
||||
return false
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user