@@ -83,7 +83,7 @@ func (controller *GrpcControllerImpl) AddRepo(ctx context.Context, req *pb.AddRe
8383 * pb.Empty , error ) {
8484
8585 // Mapping to sql package specified struct type
86- gitMaterials := make ([]* sql.GitMaterial , 0 )
86+ gitMaterials := make ([]* sql.GitMaterial , 0 , len ( req . GitMaterialList ) )
8787 for _ , item := range req .GitMaterialList {
8888
8989 gitMaterials = append (gitMaterials , & sql.GitMaterial {
@@ -141,7 +141,7 @@ func (controller *GrpcControllerImpl) SavePipelineMaterial(ctx context.Context,
141141 * pb.Empty , error ) {
142142
143143 // Mapping to sql package specified struct type
144- ciPipelineMaterials := make ([]* sql.CiPipelineMaterial , 0 )
144+ ciPipelineMaterials := make ([]* sql.CiPipelineMaterial , 0 , len ( req . CiPipelineMaterials ) )
145145 for _ , item := range req .CiPipelineMaterials {
146146
147147 ciPipelineMaterials = append (ciPipelineMaterials , & sql.CiPipelineMaterial {
@@ -185,11 +185,13 @@ func (controller *GrpcControllerImpl) FetchChanges(ctx context.Context, req *pb.
185185 }
186186
187187 // Mapping GitCommit
188- pbGitCommits := make ([]* pb.GitCommit , 0 )
188+ pbGitCommits := make ([]* pb.GitCommit , 0 , len ( res . Commits ) )
189189 for _ , item := range res .Commits {
190190
191191 mappedCommit , err := controller .mapGitCommit (item )
192192 if err != nil {
193+ controller .logger .Debugw ("failed to map git commit from bean to proto specified type" ,
194+ "err" , err )
193195 continue
194196 }
195197 pbGitCommits = append (pbGitCommits , mappedCommit )
@@ -209,7 +211,7 @@ func (controller *GrpcControllerImpl) GetHeadForPipelineMaterials(ctx context.Co
209211 * pb.GetHeadForPipelineMaterialsResponse , error ) {
210212
211213 // Map int64 to int
212- materialIds := make ([]int , 0 )
214+ materialIds := make ([]int , 0 , len ( req . MaterialIds ) )
213215 for _ , id := range req .MaterialIds {
214216 materialIds = append (materialIds , int (id ))
215217 }
@@ -222,11 +224,13 @@ func (controller *GrpcControllerImpl) GetHeadForPipelineMaterials(ctx context.Co
222224 return nil , err
223225 }
224226 if res == nil {
227+ controller .logger .Debugw ("received nil response from GetHeadForPipelineMaterials" ,
228+ "materialIds" , materialIds )
225229 return nil , nil
226230 }
227231
228232 // Mapping to pb type
229- ciPipelineMaterialBeans := make ([]* pb.CiPipelineMaterialBean , 0 )
233+ ciPipelineMaterialBeans := make ([]* pb.CiPipelineMaterialBean , 0 , len ( res ) )
230234 for _ , item := range res {
231235
232236 var mappedGitCommit * pb.GitCommit
@@ -497,7 +501,7 @@ func (controller *GrpcControllerImpl) GetAllWebhookEventConfigForHost(ctx contex
497501 }
498502
499503 // Mapping response
500- mappedEventConfig := make ([]* pb.WebhookEventConfig , 0 )
504+ mappedEventConfig := make ([]* pb.WebhookEventConfig , 0 , len ( res ) )
501505 for _ , item := range res {
502506 mappedEventConfig = append (mappedEventConfig , controller .mapWebhookEventConfig (item ))
503507 }
@@ -547,7 +551,7 @@ func (controller *GrpcControllerImpl) GetWebhookPayloadDataForPipelineMaterialId
547551 }
548552
549553 // Mapping payloads
550- payloads := make ([]* pb.WebhookPayload , 0 )
554+ payloads := make ([]* pb.WebhookPayload , 0 , len ( res . Payloads ) )
551555 for _ , item := range res .Payloads {
552556
553557 payload := & pb.WebhookPayload {
@@ -591,7 +595,7 @@ func (controller *GrpcControllerImpl) GetWebhookPayloadFilterDataForPipelineMate
591595 }
592596
593597 // Mapping response
594- selectorsData := make ([]* pb.WebhookPayloadFilterDataSelectorResponse , 0 )
598+ selectorsData := make ([]* pb.WebhookPayloadFilterDataSelectorResponse , 0 , len ( res . SelectorsData ) )
595599 for _ , item := range res .SelectorsData {
596600
597601 selectorsData = append (selectorsData , & pb.WebhookPayloadFilterDataSelectorResponse {
@@ -610,7 +614,7 @@ func (controller *GrpcControllerImpl) GetWebhookPayloadFilterDataForPipelineMate
610614
611615func (controller * GrpcControllerImpl ) mapWebhookEventConfig (config * git.WebhookEventConfig ) * pb.WebhookEventConfig {
612616
613- selectors := make ([]* pb.WebhookEventSelectors , 0 )
617+ selectors := make ([]* pb.WebhookEventSelectors , 0 , len ( config . Selectors ) )
614618 for _ , item := range config .Selectors {
615619
616620 selector := & pb.WebhookEventSelectors {
@@ -653,7 +657,7 @@ func (controller *GrpcControllerImpl) mapWebhookEventConfig(config *git.WebhookE
653657func (controller * GrpcControllerImpl ) mapGitChanges (gitChanges * git.GitChanges ) * pb.GitChanges {
654658
655659 // Mapping Commits
656- commitsPb := make ([]* pb.Commit , 0 )
660+ commitsPb := make ([]* pb.Commit , 0 , len ( gitChanges . Commits ) )
657661 for _ , item := range gitChanges .Commits {
658662
659663 commitPb := & pb.Commit {}
@@ -713,7 +717,7 @@ func (controller *GrpcControllerImpl) mapGitChanges(gitChanges *git.GitChanges)
713717 }
714718
715719 // Mapping FileStats
716- mappedFileStats := make ([]* pb.FileStat , 0 )
720+ mappedFileStats := make ([]* pb.FileStat , 0 , len ( gitChanges . FileStats ) )
717721 for _ , item := range gitChanges .FileStats {
718722
719723 mappedFileStats = append (mappedFileStats , & pb.FileStat {
@@ -732,7 +736,7 @@ func (controller *GrpcControllerImpl) mapGitChanges(gitChanges *git.GitChanges)
732736func (controller * GrpcControllerImpl ) mapGitCommit (commit * git.GitCommit ) (* pb.GitCommit , error ) {
733737
734738 // mapping FileStats
735- mappedFileStats := make ([]* pb.FileStat , 0 )
739+ mappedFileStats := make ([]* pb.FileStat , 0 , len ( * commit . FileStats ) )
736740 if commit .FileStats != nil {
737741 for _ , item := range * commit .FileStats {
738742
0 commit comments