Selaa lähdekoodia

feat:增加限制

wangchuanjin 1 vuosi sitten
vanhempi
commit
a4964c8e6c
2 muutettua tiedostoa jossa 8 lisäystä ja 7 poistoa
  1. 0 1
      p/constant.go
  2. 8 6
      projecter/match.go

+ 0 - 1
p/constant.go

@@ -19,7 +19,6 @@ const (
 	OneDaySecond                          = 86400
 	ThreeDay                              = 259200
 	SevenDay                              = 604800
-	RelationProjectLimit                  = 50
 	Mgo_User                              = "user"
 	Mgo_Ent_User                          = "ent_user"
 	Es_Bidding                            = "bidding"

+ 8 - 6
projecter/match.go

@@ -30,6 +30,7 @@ type Match struct {
 	RelationProjectPoolSize int
 	LoadProjectPoolSize     int
 	ProjectBatch            int
+	RelationProjectLimit    int
 	Mgo_Log                 *MongodbSim
 	AllProject              *sync.Map
 	Unique                  string
@@ -54,15 +55,16 @@ func (m *Match) Execute(projectMatcher ProjectMatcher, projectUser *map[*UserInf
 				<-userPool
 				userWaitGroup.Done()
 			}()
-			newIds := []string{}
 			unique := projectMatcher.Unique(u)
-			needLength := int64(RelationProjectLimit - len((*myMatchId)[unique]))
+			needLength := int64(m.RelationProjectLimit - len((*myMatchId)[unique]))
+			if needLength <= 0 {
+				return
+			}
+			newIds := []string{}
 			searchWaitGroup := &sync.WaitGroup{}
 			for _, _id := range *_ids {
-				if (*myMatchId)[unique] == nil || !(*myMatchId)[unique][_id] {
-					if surplus := atomic.AddInt64(&needLength, -1); surplus <= 0 {
-						continue
-					}
+				if surplus := atomic.AddInt64(&needLength, -1); surplus < 0 {
+					continue
 				}
 				if _, ok := m.AllProject.Load(_id); ok {
 					continue