@@ -658,50 +658,43 @@ func (impl *CiHandlerImpl) FetchCiStatusForTriggerViewV1(appId int) ([]*pipeline
658
658
return []* pipelineConfig.CiWorkflowStatus {}, nil
659
659
}
660
660
661
- pipelinesInLatestTable , err := impl .workflowStatusLatestRepository .GetByPipelineIds (allPipelineIds )
661
+ latestStatusEntries , err := impl .workflowStatusLatestRepository .GetCiWorkflowStatusLatestByPipelineIds (allPipelineIds )
662
662
if err != nil {
663
663
impl .Logger .Errorw ("error in checking latest status table, falling back to old method" , "appId" , appId , "err" , err )
664
664
return impl .ciWorkflowRepository .FIndCiWorkflowStatusesByAppId (appId )
665
665
}
666
666
667
667
var allStatuses []* pipelineConfig.CiWorkflowStatus
668
668
669
- if len (pipelinesInLatestTable ) > 0 {
670
- statusesFromLatestTable , err := impl .fetchCiStatusFromLatestTable ( pipelinesInLatestTable )
669
+ if len (latestStatusEntries ) > 0 {
670
+ statusesFromLatestTable , err := impl .fetchCiWorkflowStatusFromLatestEntries ( latestStatusEntries )
671
671
if err != nil {
672
- impl .Logger .Errorw ("error in fetching from latest status table " , "pipelineIds " , pipelinesInLatestTable , "err" , err )
672
+ impl .Logger .Errorw ("error in fetching ci workflow status from latest ci workflow entries " , "latestStatusEntries " , latestStatusEntries , "err" , err )
673
673
return nil , err
674
674
} else {
675
675
allStatuses = append (allStatuses , statusesFromLatestTable ... )
676
676
}
677
677
}
678
678
679
- pipelinesNotInLatestTable := impl .getPipelineIdsNotInLatestTable (allPipelineIds , pipelinesInLatestTable )
679
+ pipelinesNotInLatestTable := impl .getPipelineIdsNotInLatestTable (allPipelineIds , latestStatusEntries )
680
680
681
681
if len (pipelinesNotInLatestTable ) > 0 {
682
- statusesFromComplexQuery , err := impl .fetchCiStatusUsingFallbackMethod (pipelinesNotInLatestTable )
682
+ statusesFromOldQuery , err := impl .fetchCiStatusUsingFallbackMethod (pipelinesNotInLatestTable )
683
683
if err != nil {
684
- impl .Logger .Errorw ("error in fetching using complex query " , "pipelineIds" , pipelinesNotInLatestTable , "err" , err )
684
+ impl .Logger .Errorw ("error in fetching using fallback method by pipelineIds " , "pipelineIds" , pipelinesNotInLatestTable , "err" , err )
685
685
return nil , err
686
686
} else {
687
- allStatuses = append (allStatuses , statusesFromComplexQuery ... )
687
+ allStatuses = append (allStatuses , statusesFromOldQuery ... )
688
688
}
689
689
}
690
690
691
- impl .Logger .Debugw ("hybrid ci status fetch completed" , "appId" , appId , "totalPipelines" , len (allPipelineIds ), "pipelinesFromLatestTable" , len (pipelinesInLatestTable ), "pipelinesFromOldQuery" , len (pipelinesNotInLatestTable ))
692
-
693
691
return allStatuses , nil
694
692
}
695
693
696
- // fetchCiStatusFromLatestTable fetches CI status from ci_workflow_status_latest table
697
- func (impl * CiHandlerImpl ) fetchCiStatusFromLatestTable (pipelineIds []int ) ([]* pipelineConfig.CiWorkflowStatus , error ) {
698
- latestStatusEntries , err := impl .workflowStatusLatestRepository .GetCiWorkflowStatusLatestByPipelineIds (pipelineIds )
699
- if err != nil {
700
- return nil , err
701
- }
702
-
694
+ // fetchCiWorkflowStatusFromLatestEntries fetches CI status from ci_workflow_status_latest table
695
+ func (impl * CiHandlerImpl ) fetchCiWorkflowStatusFromLatestEntries (latestCiWorkflowStatusEntries []* pipelineConfig.CiWorkflowStatusLatest ) ([]* pipelineConfig.CiWorkflowStatus , error ) {
703
696
var workflowIds []int
704
- for _ , entry := range latestStatusEntries {
697
+ for _ , entry := range latestCiWorkflowStatusEntries {
705
698
workflowIds = append (workflowIds , entry .CiWorkflowId )
706
699
}
707
700
@@ -736,21 +729,12 @@ func (impl *CiHandlerImpl) fetchCiStatusUsingFallbackMethod(pipelineIds []int) (
736
729
return statuses , nil
737
730
}
738
731
739
- // fetchWorkflowsFromLatestTable fetches workflows from ci_workflow_status_latest table
740
- func (impl * CiHandlerImpl ) fetchWorkflowsFromLatestTable (pipelineIds []int ) ([]* pipelineConfig.CiWorkflow , error ) {
741
- // Get entries from latest status table
742
- latestStatusEntries , err := impl .workflowStatusLatestRepository .GetCiWorkflowStatusLatestByPipelineIds (pipelineIds )
743
- if err != nil {
744
- return nil , err
745
- }
746
-
747
- // Extract workflow IDs
732
+ func (impl * CiHandlerImpl ) fetchWorkflowsFromLatestTable (latestStatusEntries []* pipelineConfig.CiWorkflowStatusLatest ) ([]* pipelineConfig.CiWorkflow , error ) {
748
733
var workflowIds []int
749
734
for _ , entry := range latestStatusEntries {
750
735
workflowIds = append (workflowIds , entry .CiWorkflowId )
751
736
}
752
737
753
- // Get workflows by IDs
754
738
return impl .ciWorkflowRepository .FindWorkflowsByCiWorkflowIds (workflowIds )
755
739
}
756
740
@@ -761,43 +745,45 @@ func (impl *CiHandlerImpl) fetchLastTriggeredWorkflowsHybrid(pipelineIds []int)
761
745
return []* pipelineConfig.CiWorkflow {}, nil
762
746
}
763
747
764
- pipelinesInLatestTable , err := impl .workflowStatusLatestRepository .GetByPipelineIds (pipelineIds )
748
+ latestStatusEntries , err := impl .workflowStatusLatestRepository .GetCiWorkflowStatusLatestByPipelineIds (pipelineIds )
765
749
if err != nil {
766
750
impl .Logger .Errorw ("error in checking latest status table, falling back to complex query" , "pipelineIds" , pipelineIds , "err" , err )
767
751
return impl .ciWorkflowRepository .FindLastTriggeredWorkflowByCiIds (pipelineIds )
768
752
}
769
753
770
754
var allWorkflows []* pipelineConfig.CiWorkflow
771
755
772
- if len (pipelinesInLatestTable ) > 0 {
773
- workflowsFromLatestTable , err := impl .fetchWorkflowsFromLatestTable (pipelinesInLatestTable )
756
+ if len (latestStatusEntries ) > 0 {
757
+ workflowsFromLatestTable , err := impl .fetchWorkflowsFromLatestTable (latestStatusEntries )
774
758
if err != nil {
775
- impl .Logger .Errorw ("error in fetching from latest status table" , "pipelineIds " , pipelinesInLatestTable , "err" , err )
759
+ impl .Logger .Errorw ("error in fetching from latest status table" , "latestStatusEntries " , latestStatusEntries , "err" , err )
776
760
return nil , err
777
761
} else {
778
762
allWorkflows = append (allWorkflows , workflowsFromLatestTable ... )
779
763
}
780
764
}
781
765
782
- pipelinesNotInLatestTable := impl .getPipelineIdsNotInLatestTable (pipelineIds , pipelinesInLatestTable )
766
+ pipelinesNotInLatestTable := impl .getPipelineIdsNotInLatestTable (pipelineIds , latestStatusEntries )
783
767
784
768
if len (pipelinesNotInLatestTable ) > 0 {
785
- workflowsFromComplexQuery , err := impl .ciWorkflowRepository .FindLastTriggeredWorkflowByCiIds (pipelinesNotInLatestTable )
769
+ workflowsFromOldQuery , err := impl .ciWorkflowRepository .FindLastTriggeredWorkflowByCiIds (pipelinesNotInLatestTable )
786
770
if err != nil {
787
- impl .Logger .Errorw ("error in fetching using complex query" , "pipelineIds" , pipelinesNotInLatestTable , "err" , err )
771
+ impl .Logger .Errorw ("error in fetching using old query by pipeline ids " , "pipelineIds" , pipelinesNotInLatestTable , "err" , err )
788
772
return nil , err
789
773
} else {
790
- allWorkflows = append (allWorkflows , workflowsFromComplexQuery ... )
774
+ allWorkflows = append (allWorkflows , workflowsFromOldQuery ... )
791
775
}
792
776
}
793
777
794
- impl .Logger .Debugw ("hybrid workflow fetch completed" , "totalPipelines" , len (pipelineIds ), "pipelinesFromLatestTable" , len (pipelinesInLatestTable ), "pipelinesFromOldQuery" , len (pipelinesNotInLatestTable ))
795
-
796
778
return allWorkflows , nil
797
779
}
798
780
799
781
// getPipelineIdsNotInLatestTable finds pipeline IDs that are NOT in the latest status table
800
- func (impl * CiHandlerImpl ) getPipelineIdsNotInLatestTable (allPipelineIds , pipelinesInLatestTable []int ) []int {
782
+ func (impl * CiHandlerImpl ) getPipelineIdsNotInLatestTable (allPipelineIds []int , latestStatusEntries []* pipelineConfig.CiWorkflowStatusLatest ) []int {
783
+ var pipelinesInLatestTable []int
784
+ for _ , entry := range latestStatusEntries {
785
+ pipelinesInLatestTable = append (pipelinesInLatestTable , entry .PipelineId )
786
+ }
801
787
pipelineIdMap := make (map [int ]bool )
802
788
for _ , id := range pipelinesInLatestTable {
803
789
pipelineIdMap [id ] = true
0 commit comments