@@ -736,6 +736,7 @@ func GetCommitAuthorSignedStatus(
736736 userSummary * UserCommitSummary ,
737737 signed * []* UserCommitSummary ,
738738 unsigned * []* UserCommitSummary ,
739+ mu * sync.Mutex ,
739740) {
740741 f := logrus.Fields {
741742 "functionName" : "github.github_repository.GetCommitAuthorsSignedStatuses" ,
@@ -762,17 +763,23 @@ func GetCommitAuthorSignedStatus(
762763 if ok {
763764 if cachedUser == nil {
764765 log .WithFields (f ).Debugf ("per-project cache: unsigned, user is null" )
766+ mu .Lock ()
765767 * unsigned = append (* unsigned , userSummary )
768+ mu .Unlock ()
766769 return
767770 }
768771 userSummary .Affiliated = affiliated
769772 if authorized {
770773 userSummary .Authorized = authorized
771774 log .WithFields (f ).Debugf ("per-project cache: signed" )
775+ mu .Lock ()
772776 * signed = append (* signed , userSummary )
777+ mu .Unlock ()
773778 } else {
774779 log .WithFields (f ).Debugf ("per-project cache: unsigned, authorized is false" )
780+ mu .Lock ()
775781 * unsigned = append (* unsigned , userSummary )
782+ mu .Unlock ()
776783 }
777784 return
778785 }
@@ -788,7 +795,9 @@ func GetCommitAuthorSignedStatus(
788795 if ok {
789796 if cachedUser == nil {
790797 log .WithFields (f ).Debugf ("general cache: unsigned, user is null" )
798+ mu .Lock ()
791799 * unsigned = append (* unsigned , userSummary )
800+ mu .Unlock ()
792801 ModelProjectUserCache .Set (projectCacheKey , nil , false , false )
793802 return
794803 }
@@ -797,7 +806,9 @@ func GetCommitAuthorSignedStatus(
797806 if signedErr != nil {
798807 log .WithFields (f ).WithError (signedErr ).Warnf ("has user signed error - user: %+v, project: %s" , user , projectID )
799808 log .WithFields (f ).Debugf ("general cache: unsigned, hasUserSigned error" )
809+ mu .Lock ()
800810 * unsigned = append (* unsigned , userSummary )
811+ mu .Unlock ()
801812 ModelProjectUserCache .Set (projectCacheKey , user , false , false )
802813 return
803814 }
@@ -810,16 +821,22 @@ func GetCommitAuthorSignedStatus(
810821 userSummary .Authorized = * userSigned
811822 if userSummary .Authorized {
812823 log .WithFields (f ).Debugf ("general cache: signed" )
824+ mu .Lock ()
813825 * signed = append (* signed , userSummary )
826+ mu .Unlock ()
814827 ModelProjectUserCache .Set (projectCacheKey , user , true , userSummary .Affiliated )
815828 } else {
816829 log .WithFields (f ).Debugf ("general cache: unsigned, authorized is false" )
830+ mu .Lock ()
817831 * unsigned = append (* unsigned , userSummary )
832+ mu .Unlock ()
818833 ModelProjectUserCache .Set (projectCacheKey , user , false , userSummary .Affiliated )
819834 }
820835 } else {
821836 log .WithFields (f ).Debugf ("general cache: unsigned, userSigned is null" )
837+ mu .Lock ()
822838 * unsigned = append (* unsigned , userSummary )
839+ mu .Unlock ()
823840 ModelProjectUserCache .Set (projectCacheKey , user , false , userSummary .Affiliated )
824841 }
825842 return
@@ -864,7 +881,9 @@ func GetCommitAuthorSignedStatus(
864881 log .WithFields (f ).Debugf ("unable to find user for commit author - sha: %s, user ID: %s, username: %s, email: %s" ,
865882 userSummary .SHA , commitAuthorID , commitAuthorUsername , commitAuthorEmail )
866883 log .WithFields (f ).Debugf ("store caches: unsigned, user is null" )
884+ mu .Lock ()
867885 * unsigned = append (* unsigned , userSummary )
886+ mu .Unlock ()
868887 ModelProjectUserCache .Set (projectCacheKey , nil , false , false )
869888 ModelUserCache .Set (cacheKey , nil )
870889 return
@@ -875,7 +894,9 @@ func GetCommitAuthorSignedStatus(
875894 if signedErr != nil {
876895 log .WithFields (f ).WithError (signedErr ).Warnf ("has user signed error - user: %+v, project: %s" , user , projectID )
877896 log .WithFields (f ).Debugf ("store caches: unsigned, hasUserSigned error" )
897+ mu .Lock ()
878898 * unsigned = append (* unsigned , userSummary )
899+ mu .Unlock ()
879900 ModelProjectUserCache .Set (projectCacheKey , user , false , false )
880901 ModelUserCache .Set (cacheKey , user )
881902 return
@@ -889,18 +910,24 @@ func GetCommitAuthorSignedStatus(
889910 userSummary .Authorized = * userSigned
890911 if userSummary .Authorized {
891912 log .WithFields (f ).Debugf ("store caches: signed" )
913+ mu .Lock ()
892914 * signed = append (* signed , userSummary )
915+ mu .Unlock ()
893916 ModelProjectUserCache .Set (projectCacheKey , user , true , userSummary .Affiliated )
894917 ModelUserCache .Set (cacheKey , user )
895918 } else {
896919 log .WithFields (f ).Debugf ("store caches: unsigned, authorized is false" )
920+ mu .Lock ()
897921 * unsigned = append (* unsigned , userSummary )
922+ mu .Unlock ()
898923 ModelProjectUserCache .Set (projectCacheKey , user , false , userSummary .Affiliated )
899924 ModelUserCache .Set (cacheKey , user )
900925 }
901926 } else {
902927 log .WithFields (f ).Debugf ("store caches: unsigned, userSigned is null" )
928+ mu .Lock ()
903929 * unsigned = append (* unsigned , userSummary )
930+ mu .Unlock ()
904931 ModelProjectUserCache .Set (projectCacheKey , user , false , userSummary .Affiliated )
905932 ModelUserCache .Set (cacheKey , user )
906933 }
@@ -918,23 +945,35 @@ func GetCommitAuthorsSignedStatuses(
918945 "functionName" : "github.github_repository.GetCommitAuthorsSignedStatuses" ,
919946 "projectID" : projectID ,
920947 }
921- signed := make ([]* UserCommitSummary , 0 )
922- unsigned := make ([]* UserCommitSummary , 0 )
923-
924- // triage signed and unsigned users
925948 log .WithFields (f ).Debugf ("checking %d commit authors" , len (authors ))
926- for _ , userSummary := range authors {
927- if userSummary == nil || ! userSummary .IsValid () {
928- if userSummary == nil {
929- log .WithFields (f ).Debugf ("invalid user summary: nil" )
930- } else {
931- log .WithFields (f ).Debugf ("invalid user summary: %+v" , * userSummary )
949+
950+ signed := make ([]* UserCommitSummary , 0 , len (authors ))
951+ unsigned := make ([]* UserCommitSummary , 0 , len (authors ))
952+ var mu sync.Mutex
953+ var wg sync.WaitGroup
954+
955+ for _ , us := range authors {
956+ wg .Add (1 )
957+ go func (userSummary * UserCommitSummary ) {
958+ defer wg .Done ()
959+
960+ if userSummary == nil || ! userSummary .IsValid () {
961+ if userSummary == nil {
962+ log .WithFields (f ).Debugf ("invalid user summary: nil" )
963+ } else {
964+ log .WithFields (f ).Debugf ("invalid user summary: %+v" , userSummary )
965+ }
966+ mu .Lock ()
967+ unsigned = append (unsigned , userSummary )
968+ mu .Unlock ()
969+ return
932970 }
933- unsigned = append (unsigned , userSummary )
934- continue
935- }
936- GetCommitAuthorSignedStatus (ctx , usersService , hasUserSigned , projectID , userSummary , & signed , & unsigned )
971+
972+ GetCommitAuthorSignedStatus (ctx , usersService , hasUserSigned , projectID , userSummary , & signed , & unsigned , & mu )
973+ }(us )
937974 }
975+
976+ wg .Wait ()
938977 return signed , unsigned
939978}
940979
@@ -966,7 +1005,7 @@ func GetCommitAuthorsSignedStatusesST(
9661005 unsigned = append (unsigned , userSummary )
9671006 continue
9681007 }
969- GetCommitAuthorSignedStatus (ctx , usersService , hasUserSigned , projectID , userSummary , & signed , & unsigned )
1008+ GetCommitAuthorSignedStatus (ctx , usersService , hasUserSigned , projectID , userSummary , & signed , & unsigned , & sync. Mutex {} )
9701009 }
9711010 return signed , unsigned
9721011}
0 commit comments