Batch-load related data in actions run, job, and task API endpoints#37032
Batch-load related data in actions run, job, and task API endpoints#37032wxiaoguang merged 25 commits intogo-gitea:mainfrom
Conversation
15f60ab to
88787d9
Compare
There was a problem hiding this comment.
Pull request overview
This PR optimizes GitHub Actions API list endpoints by reducing per-item database queries through batch-loading related models (repos, trigger users, job/task attributes) before converting results to API structs, and adjusts routing middleware accordingly.
Changes:
- Batch-load run trigger users and repositories in
ListRuns, and job run/repo references inListJobs. - Batch-load task/job/run references in
ListActionTasks. - Remove
context.ReferencesGitRepo(true)from the repo/actionsroute group and add integration tests for user-level run/job listing.
Reviewed changes
Copilot reviewed 4 out of 4 changed files in this pull request and generated 4 comments.
| File | Description |
|---|---|
| tests/integration/api_actions_run_test.go | Adds integration coverage for /api/v1/user/actions/runs and /api/v1/user/actions/jobs responses. |
| routers/api/v1/shared/action.go | Batch-loads runs/jobs dependencies to avoid per-item repo/user queries in shared listing helpers. |
| routers/api/v1/repo/action.go | Batch-loads task attributes prior to conversion in repo task listing endpoint. |
| routers/api/v1/api.go | Removes Git repo reference middleware from repo /actions API routes. |
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
b729742 to
7a87efe
Compare
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.
7a87efe to
4c02528
Compare
|
Sorry about the force push. I forced a squashed fix, then again to unsquash it. |
|
Please click "Resolve conversation" on all addressed comments so we know what is still pending. |
Add ActionTask.LoadJobAttributes that loads Job and its attributes (Run, Repo) without loading Steps. Use it in ToActionTask so the task list endpoint no longer issues per-task step queries. Co-Authored-By: Claude (Opus)
Assign the already-available repo parameter to run.Repo so LoadAttributes skips the redundant repo lookup, and remove the TriggerUser nil guard since LoadAttributes handles nil checks internally. Co-Authored-By: Claude (Opus)
…x/actions-api-n-plus-1 # Conflicts: # services/convert/convert.go
If a job references a run that was deleted between the job query and the run query, the map lookup returns nil and the next line panics. Nil-check before setting j.Run.Repo. Co-Authored-By: Claude <noreply@anthropic.com> (claude-opus-4-7)
This branch indicates server-side data inconsistency (the batch loader couldn't resolve the run or repo for a job we just listed), not a missing resource the client asked for. APIErrorInternal returns 500 and logs the error detail server-side instead of echoing the job ID in the response body. Co-Authored-By: Claude <noreply@anthropic.com> (claude-opus-4-7)
|
Thanks for the review. Finding 1 (wrong HTTP status in Finding 2 ( Comment authored by Claude. |
When isRepoLevel, ctx.Repo.Repository (with Owner populated by middleware) is already assigned to every run, so the subsequent LoadRepos + LoadOwners queries are redundant and overwrite the pre-assigned pointers. Add a repo-level ListRuns integration test covering the branch. Co-Authored-By: Claude (Opus 4.7) <noreply@anthropic.com>
|
Remaining findings fixed in 8da8495. |
There was a problem hiding this comment.
Pull request overview
Copilot reviewed 15 out of 15 changed files in this pull request and generated 2 comments.
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
* origin/main: Refactor CI workflows (go-gitea#37487) Allow multiple projects per issue and pull requests (go-gitea#36784) [skip ci] Updated translations via Crowdin Refactor compare diff/pull page (1) (go-gitea#37481) Fix review submission from single-commit PR view (go-gitea#37475) Refactor integration tests infrastructure (go-gitea#37462) Fix allow maintainer edit permission check (go-gitea#37479) Serve OpenAPI 3.0 spec at /openapi.v1.json (go-gitea#37038) Batch-load related data in actions run, job, and task API endpoints (go-gitea#37032) Add DEFAULT_TITLE_SOURCE setting for pull request title default behavior (go-gitea#37465) Fix compare dropdown for branches without common history (go-gitea#37470) FIX: URL sanitization to handle schemeless credentials (go-gitea#37440) Refactor pull request view (4) (go-gitea#37451) # Conflicts: # modules/indexer/issues/elasticsearch/elasticsearch.go
Avoid per-item DB queries in ListRuns, ListJobs, and ListActionTasks by batch-loading trigger users, repositories, and task attributes before the conversion loop. Remove ReferencesGitRepo from the /actions route group since no task/run endpoints use it.
I ran into this in another fork that will remain nameless, their action page wouldn't load for me.
Added tests for these endpoints as well.
This was built using Claude Code with Opus.