|
9 | 9 | "fmt" |
10 | 10 | "net/http" |
11 | 11 | "regexp" |
| 12 | + "runtime" |
12 | 13 | "strconv" |
13 | 14 | "strings" |
14 | 15 | "sync" |
@@ -739,7 +740,7 @@ func GetCommitAuthorSignedStatus( |
739 | 740 | mu *sync.Mutex, |
740 | 741 | ) { |
741 | 742 | f := logrus.Fields{ |
742 | | - "functionName": "github.github_repository.GetCommitAuthorsSignedStatuses", |
| 743 | + "functionName": "github.github_repository.GetCommitAuthorSignedStatus", |
743 | 744 | "projectID": projectID, |
744 | 745 | "userSummary": *userSummary, |
745 | 746 | } |
@@ -933,16 +934,17 @@ func GetCommitAuthorSignedStatus( |
933 | 934 | } |
934 | 935 | } |
935 | 936 |
|
936 | | -// GetCommitAuthorsSignedStatuses returns two slices of UserCommitSummary - signed and unsigned for the given project and commit authors |
937 | | -func GetCommitAuthorsSignedStatuses( |
| 937 | +// GetCommitAuthorsSignedStatusesUL returns two slices of UserCommitSummary - signed and unsigned for the given project and commit authors |
| 938 | +// UL suffix = unbounded concurrency version (launches a goroutine for each author without limiting concurrency) |
| 939 | +func GetCommitAuthorsSignedStatusesUL( |
938 | 940 | ctx context.Context, |
939 | 941 | usersService users.Service, |
940 | 942 | hasUserSigned func(context.Context, *models.User, string) (*bool, *bool, error), |
941 | 943 | projectID string, |
942 | 944 | authors []*UserCommitSummary, |
943 | 945 | ) ([]*UserCommitSummary, []*UserCommitSummary) { |
944 | 946 | f := logrus.Fields{ |
945 | | - "functionName": "github.github_repository.GetCommitAuthorsSignedStatuses", |
| 947 | + "functionName": "github.github_repository.GetCommitAuthorsSignedStatusesUL", |
946 | 948 | "projectID": projectID, |
947 | 949 | } |
948 | 950 | log.WithFields(f).Debugf("checking %d commit authors", len(authors)) |
@@ -977,6 +979,50 @@ func GetCommitAuthorsSignedStatuses( |
977 | 979 | return signed, unsigned |
978 | 980 | } |
979 | 981 |
|
| 982 | +func GetCommitAuthorsSignedStatuses( |
| 983 | + ctx context.Context, |
| 984 | + usersService users.Service, |
| 985 | + hasUserSigned func(context.Context, *models.User, string) (*bool, *bool, error), |
| 986 | + projectID string, |
| 987 | + authors []*UserCommitSummary, |
| 988 | +) ([]*UserCommitSummary, []*UserCommitSummary) { |
| 989 | + f := logrus.Fields{ |
| 990 | + "functionName": "github.github_repository.GetCommitAuthorsSignedStatuses", |
| 991 | + "projectID": projectID, |
| 992 | + } |
| 993 | + log.WithFields(f).Debugf("checking %d commit authors", len(authors)) |
| 994 | + signed := make([]*UserCommitSummary, 0, len(authors)) |
| 995 | + unsigned := make([]*UserCommitSummary, 0, len(authors)) |
| 996 | + var mu sync.Mutex |
| 997 | + var wg sync.WaitGroup |
| 998 | + maxConc := runtime.NumCPU() |
| 999 | + if maxConc < 1 { |
| 1000 | + maxConc = 1 |
| 1001 | + } |
| 1002 | + sem := make(chan struct{}, maxConc) |
| 1003 | + for _, us := range authors { |
| 1004 | + if us == nil || !us.IsValid() { |
| 1005 | + log.WithFields(f).Debugf("invalid user summary: %v", us) |
| 1006 | + mu.Lock() |
| 1007 | + unsigned = append(unsigned, us) |
| 1008 | + mu.Unlock() |
| 1009 | + continue |
| 1010 | + } |
| 1011 | + |
| 1012 | + wg.Add(1) |
| 1013 | + sem <- struct{}{} // acquire a slot |
| 1014 | + go func(userSummary *UserCommitSummary) { |
| 1015 | + defer wg.Done() |
| 1016 | + defer func() { <-sem }() // release slot |
| 1017 | + |
| 1018 | + GetCommitAuthorSignedStatus(ctx, usersService, hasUserSigned, projectID, userSummary, &signed, &unsigned, &mu) |
| 1019 | + }(us) |
| 1020 | + } |
| 1021 | + |
| 1022 | + wg.Wait() |
| 1023 | + return signed, unsigned |
| 1024 | +} |
| 1025 | + |
980 | 1026 | // GetCommitAuthorsSignedStatusesST returns two slices of UserCommitSummary - signed and unsigned for the given project and commit authors |
981 | 1027 | // ST suffix = single threaded version |
982 | 1028 | func GetCommitAuthorsSignedStatusesST( |
|
0 commit comments