@@ -4628,6 +4628,19 @@ func (repo repository) GetClaGroupCorporateContributors(ctx context.Context, cla
46284628 totalCountChannel := make (chan int64 , 1 )
46294629 go repo .getTotalCorporateContributorCount (ctx , claGroupID , companyID , searchTerm , totalCountChannel )
46304630
4631+ totalCount := <- totalCountChannel
4632+ log .WithFields (f ).Debugf ("total corporate contributor count: %d" , totalCount )
4633+ // If the page size is nil, set it to the default
4634+ if pageSize == nil {
4635+ pageSize = aws .Int64 (10 )
4636+ }
4637+
4638+ if * pageSize > totalCount {
4639+ pageSize = aws .Int64 (totalCount )
4640+ }
4641+
4642+ log .WithFields (f ).Debugf ("total corporate contributor count: %d, page size: %d" , totalCount , * pageSize )
4643+
46314644 condition := expression .Key ("signature_project_id" ).Equal (expression .Value (claGroupID ))
46324645 // if companyID != nil {
46334646 // sortKey := fmt.Sprintf("%s#%v#%v#%v", utils.ClaTypeECLA, true, true, *companyID)
@@ -4660,11 +4673,6 @@ func (repo repository) GetClaGroupCorporateContributors(ctx context.Context, cla
46604673 return nil , err
46614674 }
46624675
4663- // If the page size is nil, set it to the default
4664- if pageSize == nil {
4665- pageSize = aws .Int64 (10 )
4666- }
4667-
46684676 // Assemble the query input parameters
46694677 queryInput := & dynamodb.QueryInput {
46704678 ExpressionAttributeNames : expr .Names (),
@@ -4692,7 +4700,9 @@ func (repo repository) GetClaGroupCorporateContributors(ctx context.Context, cla
46924700 out := & models.CorporateContributorList {List : make ([]* models.CorporateContributor , 0 )}
46934701 var lastEvaluatedKey string
46944702
4695- for ok := true ; ok ; ok = lastEvaluatedKey != "" {
4703+ currentCount := int64 (0 )
4704+
4705+ for ok := true ; ok ; ok = lastEvaluatedKey != "" && currentCount < * pageSize {
46964706 // Make the DynamoDB Query API call
46974707 log .WithFields (f ).Debug ("querying signatures..." )
46984708 results , queryErr := repo .dynamoDBClient .Query (queryInput )
@@ -4766,26 +4776,28 @@ func (repo repository) GetClaGroupCorporateContributors(ctx context.Context, cla
47664776 SignatureApproved : sig .SignatureApproved ,
47674777 SignatureSigned : sig .SignatureSigned ,
47684778 })
4779+
4780+ // Increment the current count
4781+ currentCount ++
4782+ if currentCount >= * pageSize {
4783+ break
4784+ }
47694785 }
47704786
4771- if results .LastEvaluatedKey ["signature_id" ] != nil {
4787+ if results .LastEvaluatedKey ["signature_id" ] != nil && currentCount < * pageSize {
47724788 lastEvaluatedKey = * results .LastEvaluatedKey ["signature_id" ].S
47734789 queryInput .ExclusiveStartKey = results .LastEvaluatedKey
47744790 } else {
47754791 lastEvaluatedKey = ""
47764792 }
47774793
4778- if int64 (len (out .List )) >= * pageSize {
4779- break
4780- }
4781-
47824794 }
47834795 sort .Slice (out .List , func (i , j int ) bool {
47844796 return out .List [i ].Name < out .List [j ].Name
47854797 })
47864798
4787- out .ResultCount = int64 ( len ( out . List ))
4788- out .TotalCount = <- totalCountChannel
4799+ out .ResultCount = currentCount
4800+ out .TotalCount = totalCount
47894801 out .NextKey = lastEvaluatedKey
47904802
47914803 return out , nil
0 commit comments