mirror of
				https://github.com/TeaOSLab/EdgeAPI.git
				synced 2025-11-04 07:50:25 +08:00 
			
		
		
		
	优化代码
This commit is contained in:
		@@ -97,16 +97,12 @@ func (this *HTTPCacheTaskKeyService) ValidateHTTPCacheTaskKeys(ctx context.Conte
 | 
			
		||||
		}
 | 
			
		||||
 | 
			
		||||
		var serverClusterId = int64(server.ClusterId)
 | 
			
		||||
		if serverClusterId == 0 {
 | 
			
		||||
			if clusterId > 0 {
 | 
			
		||||
				serverClusterId = clusterId
 | 
			
		||||
			} else {
 | 
			
		||||
				pbFailResults = append(pbFailResults, &pb.ValidateHTTPCacheTaskKeysResponse_FailKey{
 | 
			
		||||
					Key:        key,
 | 
			
		||||
					ReasonCode: "requireClusterId",
 | 
			
		||||
				})
 | 
			
		||||
				continue
 | 
			
		||||
			}
 | 
			
		||||
		if serverClusterId == 0 && clusterId <= 0 {
 | 
			
		||||
			pbFailResults = append(pbFailResults, &pb.ValidateHTTPCacheTaskKeysResponse_FailKey{
 | 
			
		||||
				Key:        key,
 | 
			
		||||
				ReasonCode: "requireClusterId",
 | 
			
		||||
			})
 | 
			
		||||
			continue
 | 
			
		||||
		}
 | 
			
		||||
	}
 | 
			
		||||
 | 
			
		||||
 
 | 
			
		||||
@@ -34,7 +34,7 @@ type CommandRequestWaiting struct {
 | 
			
		||||
 | 
			
		||||
func (this *CommandRequestWaiting) Close() {
 | 
			
		||||
	defer func() {
 | 
			
		||||
		recover()
 | 
			
		||||
		_ = recover()
 | 
			
		||||
	}()
 | 
			
		||||
 | 
			
		||||
	close(this.Chan)
 | 
			
		||||
@@ -207,7 +207,7 @@ func (this *NodeService) NodeStream(server pb.NodeService_NodeStreamServer) erro
 | 
			
		||||
		func(req *pb.NodeStreamMessage) {
 | 
			
		||||
			// 因为 responseChan.Chan 有被关闭的风险,所以我们使用recover防止panic
 | 
			
		||||
			defer func() {
 | 
			
		||||
				recover()
 | 
			
		||||
				_ = recover()
 | 
			
		||||
			}()
 | 
			
		||||
 | 
			
		||||
			nodeLocker.Lock()
 | 
			
		||||
 
 | 
			
		||||
@@ -2917,8 +2917,14 @@ func (this *ServerService) CopyServerConfig(ctx context.Context, req *pb.CopySer
 | 
			
		||||
			if err != nil {
 | 
			
		||||
				return nil, err
 | 
			
		||||
			}
 | 
			
		||||
			if req.TargetUserId <= 0 {
 | 
			
		||||
				req.TargetUserId = userId
 | 
			
		||||
			}
 | 
			
		||||
 | 
			
		||||
			// 此时如果用户为0,则同步到未分配用户的服务
 | 
			
		||||
			// 此时如果用户为0,则同步到未分配用户的网站
 | 
			
		||||
		} else {
 | 
			
		||||
			// 只能同步到自己的网站
 | 
			
		||||
			req.TargetUserId = userId
 | 
			
		||||
		}
 | 
			
		||||
		err = models.SharedServerDAO.CopyServerConfigToUser(tx, req.ServerId, req.TargetUserId, req.ConfigCode)
 | 
			
		||||
		if err != nil {
 | 
			
		||||
 
 | 
			
		||||
@@ -177,7 +177,7 @@ func (this *ServerBandwidthStatService) FindServerBandwidthStats(ctx context.Con
 | 
			
		||||
		req.Algo = bandwidthAlgo
 | 
			
		||||
	}
 | 
			
		||||
 | 
			
		||||
	var stats = []*models.ServerBandwidthStat{}
 | 
			
		||||
	var stats []*models.ServerBandwidthStat
 | 
			
		||||
	if len(req.Day) > 0 {
 | 
			
		||||
		stats, err = models.SharedServerBandwidthStatDAO.FindAllServerStatsWithDay(tx, req.ServerId, req.Day, req.Algo == systemconfigs.BandwidthAlgoAvg)
 | 
			
		||||
	} else if len(req.Month) > 0 {
 | 
			
		||||
@@ -398,7 +398,7 @@ func (this *ServerBandwidthStatService) FindDailyServerBandwidthStatsBetweenDays
 | 
			
		||||
		return nil, errors.New("invalid dayTo '" + req.DayTo + "'")
 | 
			
		||||
	}
 | 
			
		||||
 | 
			
		||||
	var pbStats = []*pb.FindDailyServerBandwidthStatsBetweenDaysResponse_Stat{}
 | 
			
		||||
	var pbStats []*pb.FindDailyServerBandwidthStatsBetweenDaysResponse_Stat
 | 
			
		||||
	var pbNthStat *pb.FindDailyServerBandwidthStatsBetweenDaysResponse_Stat
 | 
			
		||||
	if req.ServerId > 0 { // 服务统计
 | 
			
		||||
		pbStats, err = models.SharedServerBandwidthStatDAO.FindBandwidthStatsBetweenDays(tx, req.ServerId, req.DayFrom, req.DayTo, req.Algo == systemconfigs.BandwidthAlgoAvg)
 | 
			
		||||
 
 | 
			
		||||
		Reference in New Issue
	
	Block a user