improve: server list lock

This commit is contained in:
naiba
2025-01-04 01:10:16 +08:00
parent efdae906c2
commit 81a08a38da
2 changed files with 25 additions and 21 deletions

View File

@@ -85,7 +85,8 @@ func listServiceHistory(c *gin.Context) ([]*model.ServiceInfos, error) {
singleton.ServerLock.RLock()
server, ok := singleton.ServerList[id]
if !ok {
singleton.ServerLock.RUnlock()
if !ok || server == nil {
return nil, singleton.Localizer.ErrorT("server not found")
}
@@ -95,7 +96,6 @@ func listServiceHistory(c *gin.Context) ([]*model.ServiceInfos, error) {
if server.HideForGuest && !authorized {
return nil, singleton.Localizer.ErrorT("unauthorized")
}
singleton.ServerLock.RUnlock()
var serviceHistories []*model.ServiceHistory
if err := singleton.DB.Model(&model.ServiceHistory{}).Select("service_id, created_at, server_id, avg_delay").