Skip to content

Commit 79449e0

Browse files
Final WIP update 2
Signed-off-by: Lukasz Gryglicki <[email protected]> Assisted by [OpenAI](https://platform.openai.com/) Assisted by [GitHub Copilot](https://github.com/features/copilot)
1 parent 34f0dcd commit 79449e0

File tree

1 file changed

+50
-4
lines changed

1 file changed

+50
-4
lines changed

cla-backend-go/github/github_repository.go

Lines changed: 50 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@ import (
99
"fmt"
1010
"net/http"
1111
"regexp"
12+
"runtime"
1213
"strconv"
1314
"strings"
1415
"sync"
@@ -739,7 +740,7 @@ func GetCommitAuthorSignedStatus(
739740
mu *sync.Mutex,
740741
) {
741742
f := logrus.Fields{
742-
"functionName": "github.github_repository.GetCommitAuthorsSignedStatuses",
743+
"functionName": "github.github_repository.GetCommitAuthorSignedStatus",
743744
"projectID": projectID,
744745
"userSummary": *userSummary,
745746
}
@@ -933,16 +934,17 @@ func GetCommitAuthorSignedStatus(
933934
}
934935
}
935936

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(
938940
ctx context.Context,
939941
usersService users.Service,
940942
hasUserSigned func(context.Context, *models.User, string) (*bool, *bool, error),
941943
projectID string,
942944
authors []*UserCommitSummary,
943945
) ([]*UserCommitSummary, []*UserCommitSummary) {
944946
f := logrus.Fields{
945-
"functionName": "github.github_repository.GetCommitAuthorsSignedStatuses",
947+
"functionName": "github.github_repository.GetCommitAuthorsSignedStatusesUL",
946948
"projectID": projectID,
947949
}
948950
log.WithFields(f).Debugf("checking %d commit authors", len(authors))
@@ -977,6 +979,50 @@ func GetCommitAuthorsSignedStatuses(
977979
return signed, unsigned
978980
}
979981

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+
9801026
// GetCommitAuthorsSignedStatusesST returns two slices of UserCommitSummary - signed and unsigned for the given project and commit authors
9811027
// ST suffix = single threaded version
9821028
func GetCommitAuthorsSignedStatusesST(

0 commit comments

Comments
 (0)