This is an automated email from the ASF dual-hosted git repository.

klesh pushed a commit to branch main
in repository https://gitbox.apache.org/repos/asf/devlake.git


The following commit(s) were added to refs/heads/main by this push:
     new 9eae337c3 fix(refdiff): stop recalculating deployments without a 
previous success (#9183)
9eae337c3 is described below

commit 9eae337c35f2e06224522befd5c6855e745ba78d
Author: AwEi <[email protected]>
AuthorDate: Sun Oct 4 18:29:14 2026 +0800

    fix(refdiff): stop recalculating deployments without a previous success 
(#9183)
    
    calculateDeploymentCommitsDiff skips pairs already recorded in
    _tool_refdiff_finished_commits_diffs. For a deployment commit without a
    previous successful deployment, the LEFT JOIN yields p.commit_sha = NULL,
    while the finished pair is stored with an empty old_commit_sha. The guard
    compared '' = NULL, which is never true, so every such pair was selected
    and recalculated against the full commit history on every run.
    
    Compare against COALESCE(p.commit_sha, '') and extend the e2e test with a
    second run that must not recalculate any finished pair.
    
    Closes #9182
    
    Signed-off-by: Chen-Wei Sun <[email protected]>
---
 .../refdiff/e2e/deployment_commit_diff/commits_diffs_rerun.csv    | 1 +
 backend/plugins/refdiff/e2e/deployment_commit_diff_test.go        | 8 ++++++++
 .../plugins/refdiff/tasks/deployment_commit_diff_calculator.go    | 4 +++-
 3 files changed, 12 insertions(+), 1 deletion(-)

diff --git 
a/backend/plugins/refdiff/e2e/deployment_commit_diff/commits_diffs_rerun.csv 
b/backend/plugins/refdiff/e2e/deployment_commit_diff/commits_diffs_rerun.csv
new file mode 100644
index 000000000..225d3e438
--- /dev/null
+++ b/backend/plugins/refdiff/e2e/deployment_commit_diff/commits_diffs_rerun.csv
@@ -0,0 +1 @@
+new_commit_sha,old_commit_sha,commit_sha,sorting_index
diff --git a/backend/plugins/refdiff/e2e/deployment_commit_diff_test.go 
b/backend/plugins/refdiff/e2e/deployment_commit_diff_test.go
index 27a209898..b5f7ce8d1 100644
--- a/backend/plugins/refdiff/e2e/deployment_commit_diff_test.go
+++ b/backend/plugins/refdiff/e2e/deployment_commit_diff_test.go
@@ -58,4 +58,12 @@ func TestDeploymentCommitDiffDataFlow(t *testing.T) {
        dataflowTester.VerifyTableWithOptions(&models.FinishedCommitsDiff{}, 
e2ehelper.TableOptions{
                CSVRelPath: 
"./deployment_commit_diff/_tool_refdiff_finished_commits_diffs.csv",
        })
+
+       // a second run must not recalculate any finished pair, including 
deployments
+       // without a previous successful deployment (finished with an empty old 
sha)
+       dataflowTester.FlushTabler(&code.CommitsDiff{})
+       dataflowTester.Subtask(tasks.CalculateDeploymentCommitsDiffMeta, 
taskData)
+       dataflowTester.VerifyTableWithOptions(&code.CommitsDiff{}, 
e2ehelper.TableOptions{
+               CSVRelPath: "./deployment_commit_diff/commits_diffs_rerun.csv",
+       })
 }
diff --git a/backend/plugins/refdiff/tasks/deployment_commit_diff_calculator.go 
b/backend/plugins/refdiff/tasks/deployment_commit_diff_calculator.go
index 3f23851e0..d0fba9b83 100644
--- a/backend/plugins/refdiff/tasks/deployment_commit_diff_calculator.go
+++ b/backend/plugins/refdiff/tasks/deployment_commit_diff_calculator.go
@@ -56,13 +56,15 @@ func CalculateDeploymentCommitsDiff(taskCtx 
plugin.SubTaskContext) errors.Error
                dal.From("cicd_deployment_commits dc"),
                dal.Join("LEFT JOIN project_mapping pm ON (pm.table = 
'cicd_scopes' AND pm.row_id = dc.cicd_scope_id)"),
                dal.Join("LEFT JOIN cicd_deployment_commits p ON 
(dc.prev_success_deployment_commit_id = p.id)"),
+               // p.commit_sha is NULL when there is no previous successful 
deployment, while the
+               // finished pair is stored with an empty old_commit_sha, so 
compare against ''
                dal.Where(
                        `
                        pm.project_name = ?
                        AND NOT EXISTS (
                                SELECT 1
                                FROM _tool_refdiff_finished_commits_diffs fcd
-                               WHERE fcd.new_commit_sha = dc.commit_sha AND 
fcd.old_commit_sha = p.commit_sha
+                               WHERE fcd.new_commit_sha = dc.commit_sha AND 
fcd.old_commit_sha = COALESCE(p.commit_sha, '')
                        )
                        `,
                        data.Options.ProjectName,

Reply via email to