From ac24dad6df222dbda389a11294d22a0b65e9de0d Mon Sep 17 00:00:00 2001 From: silverwind Date: Fri, 29 May 2026 10:32:56 +0200 Subject: [PATCH] refactor(actions): simplify matrix job loading and slice sizing Use job.LoadAttributes (loads run + attributes) instead of an open-coded load plus a dead nil-check, matching the concurrency path. Pre-size the children slice to the known combination count. Co-Authored-By: Claude (Opus 4.8) --- services/actions/matrix.go | 14 +++----------- 1 file changed, 3 insertions(+), 11 deletions(-) diff --git a/services/actions/matrix.go b/services/actions/matrix.go index 767b57a26d..b216d3f345 100644 --- a/services/actions/matrix.go +++ b/services/actions/matrix.go @@ -84,16 +84,8 @@ func ReEvaluateMatrixForJobWithNeeds(ctx context.Context, job *actions_model.Act return nil, nil } - if job.Run == nil { - if err := job.LoadRun(ctx); err != nil { - return nil, fmt.Errorf("load run: %w", err) - } - } - if job.Run == nil { - return nil, errors.New("run not found after loading") - } - if err := job.Run.LoadAttributes(ctx); err != nil { - return nil, fmt.Errorf("load run attributes: %w", err) + if err := job.LoadAttributes(ctx); err != nil { + return nil, fmt.Errorf("load job attributes: %w", err) } giteaCtx := GenerateGiteaContext(ctx, job.Run, nil, job) @@ -165,7 +157,7 @@ func ReEvaluateMatrixForJobWithNeeds(ctx context.Context, job *actions_model.Act // Reuse the placeholder as the first combination and insert the rest as siblings: no phantom // skipped job is left to poison downstream needs, and siblings inherit attempt + permissions. - var children []*actions_model.ActionRunJob + children := make([]*actions_model.ActionRunJob, 0, len(combos)-1) if err := db.WithTx(ctx, func(txCtx context.Context) error { for i := 1; i < len(combos); i++ { children = append(children, &actions_model.ActionRunJob{