Skip to content

Commit 3bc8e3d

Browse files
committed
Refactor method names and variable references in CiHandlerImpl for improved clarity and consistency. Update logging and fallback logic in CI status and workflow fetching.
1 parent 01b8bc6 commit 3bc8e3d

File tree

1 file changed

+25
-39
lines changed

1 file changed

+25
-39
lines changed

pkg/pipeline/CiHandler.go

Lines changed: 25 additions & 39 deletions
Original file line numberDiff line numberDiff line change
@@ -658,50 +658,43 @@ func (impl *CiHandlerImpl) FetchCiStatusForTriggerViewV1(appId int) ([]*pipeline
658658
return []*pipelineConfig.CiWorkflowStatus{}, nil
659659
}
660660

661-
pipelinesInLatestTable, err := impl.workflowStatusLatestRepository.GetByPipelineIds(allPipelineIds)
661+
latestStatusEntries, err := impl.workflowStatusLatestRepository.GetCiWorkflowStatusLatestByPipelineIds(allPipelineIds)
662662
if err != nil {
663663
impl.Logger.Errorw("error in checking latest status table, falling back to old method", "appId", appId, "err", err)
664664
return impl.ciWorkflowRepository.FIndCiWorkflowStatusesByAppId(appId)
665665
}
666666

667667
var allStatuses []*pipelineConfig.CiWorkflowStatus
668668

669-
if len(pipelinesInLatestTable) > 0 {
670-
statusesFromLatestTable, err := impl.fetchCiStatusFromLatestTable(pipelinesInLatestTable)
669+
if len(latestStatusEntries) > 0 {
670+
statusesFromLatestTable, err := impl.fetchCiWorkflowStatusFromLatestEntries(latestStatusEntries)
671671
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)
673673
return nil, err
674674
} else {
675675
allStatuses = append(allStatuses, statusesFromLatestTable...)
676676
}
677677
}
678678

679-
pipelinesNotInLatestTable := impl.getPipelineIdsNotInLatestTable(allPipelineIds, pipelinesInLatestTable)
679+
pipelinesNotInLatestTable := impl.getPipelineIdsNotInLatestTable(allPipelineIds, latestStatusEntries)
680680

681681
if len(pipelinesNotInLatestTable) > 0 {
682-
statusesFromComplexQuery, err := impl.fetchCiStatusUsingFallbackMethod(pipelinesNotInLatestTable)
682+
statusesFromOldQuery, err := impl.fetchCiStatusUsingFallbackMethod(pipelinesNotInLatestTable)
683683
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)
685685
return nil, err
686686
} else {
687-
allStatuses = append(allStatuses, statusesFromComplexQuery...)
687+
allStatuses = append(allStatuses, statusesFromOldQuery...)
688688
}
689689
}
690690

691-
impl.Logger.Debugw("hybrid ci status fetch completed", "appId", appId, "totalPipelines", len(allPipelineIds), "pipelinesFromLatestTable", len(pipelinesInLatestTable), "pipelinesFromOldQuery", len(pipelinesNotInLatestTable))
692-
693691
return allStatuses, nil
694692
}
695693

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) {
703696
var workflowIds []int
704-
for _, entry := range latestStatusEntries {
697+
for _, entry := range latestCiWorkflowStatusEntries {
705698
workflowIds = append(workflowIds, entry.CiWorkflowId)
706699
}
707700

@@ -736,21 +729,12 @@ func (impl *CiHandlerImpl) fetchCiStatusUsingFallbackMethod(pipelineIds []int) (
736729
return statuses, nil
737730
}
738731

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) {
748733
var workflowIds []int
749734
for _, entry := range latestStatusEntries {
750735
workflowIds = append(workflowIds, entry.CiWorkflowId)
751736
}
752737

753-
// Get workflows by IDs
754738
return impl.ciWorkflowRepository.FindWorkflowsByCiWorkflowIds(workflowIds)
755739
}
756740

@@ -761,43 +745,45 @@ func (impl *CiHandlerImpl) fetchLastTriggeredWorkflowsHybrid(pipelineIds []int)
761745
return []*pipelineConfig.CiWorkflow{}, nil
762746
}
763747

764-
pipelinesInLatestTable, err := impl.workflowStatusLatestRepository.GetByPipelineIds(pipelineIds)
748+
latestStatusEntries, err := impl.workflowStatusLatestRepository.GetCiWorkflowStatusLatestByPipelineIds(pipelineIds)
765749
if err != nil {
766750
impl.Logger.Errorw("error in checking latest status table, falling back to complex query", "pipelineIds", pipelineIds, "err", err)
767751
return impl.ciWorkflowRepository.FindLastTriggeredWorkflowByCiIds(pipelineIds)
768752
}
769753

770754
var allWorkflows []*pipelineConfig.CiWorkflow
771755

772-
if len(pipelinesInLatestTable) > 0 {
773-
workflowsFromLatestTable, err := impl.fetchWorkflowsFromLatestTable(pipelinesInLatestTable)
756+
if len(latestStatusEntries) > 0 {
757+
workflowsFromLatestTable, err := impl.fetchWorkflowsFromLatestTable(latestStatusEntries)
774758
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)
776760
return nil, err
777761
} else {
778762
allWorkflows = append(allWorkflows, workflowsFromLatestTable...)
779763
}
780764
}
781765

782-
pipelinesNotInLatestTable := impl.getPipelineIdsNotInLatestTable(pipelineIds, pipelinesInLatestTable)
766+
pipelinesNotInLatestTable := impl.getPipelineIdsNotInLatestTable(pipelineIds, latestStatusEntries)
783767

784768
if len(pipelinesNotInLatestTable) > 0 {
785-
workflowsFromComplexQuery, err := impl.ciWorkflowRepository.FindLastTriggeredWorkflowByCiIds(pipelinesNotInLatestTable)
769+
workflowsFromOldQuery, err := impl.ciWorkflowRepository.FindLastTriggeredWorkflowByCiIds(pipelinesNotInLatestTable)
786770
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)
788772
return nil, err
789773
} else {
790-
allWorkflows = append(allWorkflows, workflowsFromComplexQuery...)
774+
allWorkflows = append(allWorkflows, workflowsFromOldQuery...)
791775
}
792776
}
793777

794-
impl.Logger.Debugw("hybrid workflow fetch completed", "totalPipelines", len(pipelineIds), "pipelinesFromLatestTable", len(pipelinesInLatestTable), "pipelinesFromOldQuery", len(pipelinesNotInLatestTable))
795-
796778
return allWorkflows, nil
797779
}
798780

799781
// 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+
}
801787
pipelineIdMap := make(map[int]bool)
802788
for _, id := range pipelinesInLatestTable {
803789
pipelineIdMap[id] = true

0 commit comments

Comments
 (0)