0
0
mirror of https://github.com/go-gitea/gitea.git synced 2026-06-18 20:10:04 +02:00

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) <noreply@anthropic.com>
This commit is contained in:
silverwind 2026-05-29 10:32:56 +02:00
parent 81d63c63b4
commit ac24dad6df
No known key found for this signature in database
GPG Key ID: 2E62B41C93869443

View File

@ -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{