fix: panic when syncing user external resources (#17943)

Co-authored-by: Qiu Jian <qiujian@yunionyun.com>
This commit is contained in:
Jian Qiu
2023-09-06 17:02:38 +08:00
committed by GitHub
co-authored by Qiu Jian
parent f802faf411
commit cd975efb0a
+9 -5
View File
@@ -653,17 +653,21 @@ func (manager *SUserManager) FetchScopeResources(userIds []string) (map[string]a
}
result := map[string]api.ExternalResourceInfo{}
for _, res := range ret {
if res.ResCount <= 0 {
continue
}
_, ok := result[res.OwnerId]
if !ok && res.ResCount > 0 {
if ok {
result[res.OwnerId].ExtResource[res.Resource] = res.ResCount
} else {
result[res.OwnerId] = api.ExternalResourceInfo{
ExtResource: map[string]int{},
ExtResource: map[string]int{
res.Resource: res.ResCount,
},
ExtResourcesLastUpdate: res.LastUpdate,
ExtResourcesNextUpdate: res.LastUpdate.Add(time.Duration(options.Options.FetchScopeResourceCountIntervalSeconds) * time.Second),
}
}
if res.ResCount > 0 {
result[res.OwnerId].ExtResource[res.Resource] = res.ResCount
}
}
return result, nil
}