Skip to content

Commit 7a87efe

Browse files
committed
Skip redundant LoadAttributes in convert layer when batch-loaded
ToActionWorkflowRun and ToActionTask both call LoadAttributes unconditionally, which re-queries repos and loads unused task steps even when the list handler has already batch-loaded everything. Guard both with a nil check on the already-populated field: skip LoadAttributes when TriggerUser (runs) or Job (tasks) is set.
1 parent 43d2ace commit 7a87efe

1 file changed

Lines changed: 8 additions & 5 deletions

File tree

services/convert/convert.go

Lines changed: 8 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -224,8 +224,10 @@ func ToTag(repo *repo_model.Repository, t *git.Tag) *api.Tag {
224224

225225
// ToActionTask convert a actions_model.ActionTask to an api.ActionTask
226226
func ToActionTask(ctx context.Context, t *actions_model.ActionTask) (*api.ActionTask, error) {
227-
if err := t.LoadAttributes(ctx); err != nil {
228-
return nil, err
227+
if t.Job == nil {
228+
if err := t.LoadAttributes(ctx); err != nil {
229+
return nil, err
230+
}
229231
}
230232

231233
url := strings.TrimSuffix(setting.AppURL, "/") + t.GetRunLink()
@@ -248,9 +250,10 @@ func ToActionTask(ctx context.Context, t *actions_model.ActionTask) (*api.Action
248250
}
249251

250252
func ToActionWorkflowRun(ctx context.Context, repo *repo_model.Repository, run *actions_model.ActionRun) (*api.ActionWorkflowRun, error) {
251-
err := run.LoadAttributes(ctx)
252-
if err != nil {
253-
return nil, err
253+
if run.TriggerUser == nil {
254+
if err := run.LoadAttributes(ctx); err != nil {
255+
return nil, err
256+
}
254257
}
255258
status, conclusion := ToActionsStatus(run.Status)
256259
return &api.ActionWorkflowRun{

0 commit comments

Comments
 (0)