mirror of
https://codeberg.org/forgejo/forgejo.git
synced 2025-09-30 06:35:59 +00:00
fix: prevent initial 'blank' display of action logs view, remove unnecessary API calls (#9099)
When you access Actions logs, there is a momentary render of a partially blank screen such as this:  This is caused by the `RepoActionView` Vue component having no data. It then performs a fetch to two APIs in parallel (shown here as `/0` and `/artifacts`) to retrieve the steps and artifacts for the action run, and then it renders the page. And then, even if the job is complete and the user hasn't yet interacted to expand any logs, it performs the same API calls a second time.  This PR fixes both problems by: - Injecting the initial data for the Action's steps & Artifacts into the initial page render, and using that data into the `RepoActionView` to serve as its initial data load. - No longer unconditionally starting a second invocation of `loadJob` 1 second later, as the initial data can be used to determine whether the job is still running and requires an interval refresh. ## Checklist The [contributor guide](https://forgejo.org/docs/next/contributor/) contains information that will be helpful to first time contributors. There also are a few [conditions for merging Pull Requests in Forgejo repositories](https://codeberg.org/forgejo/governance/src/branch/main/PullRequestsAgreement.md). You are also welcome to join the [Forgejo development chatroom](https://matrix.to/#/#forgejo-development:matrix.org). ### Tests **WIP** - I added test coverage for Go changes... - [ ] in their respective `*_test.go` for unit tests. - [x] in the `tests/integration` directory if it involves interactions with a live Forgejo server. - I added test coverage for JavaScript changes... - [x] in `web_src/js/*.test.js` if it can be unit tested. - [ ] in `tests/e2e/*.test.e2e.js` if it requires interactions with a live Forgejo server (see also the [developer guide for JavaScript testing](https://codeberg.org/forgejo/forgejo/src/branch/forgejo/tests/e2e/README.md#end-to-end-tests)). ### Documentation - [ ] I created a pull request [to the documentation](https://codeberg.org/forgejo/docs) to explain to Forgejo users how to use this change. - [x] I did not document these changes and I do not expect someone else to do it. ### Release notes - [ ] I do not want this change to show in the release notes. - [x] I want the title to show in the release notes with a link to this pull request. - [ ] I want the content of the `release-notes/<pull request number>.md` to be be used for the release notes instead of the title. <!--start release-notes-assistant--> ## Release notes <!--URL:https://codeberg.org/forgejo/forgejo--> - User Interface bug fixes - [PR](https://codeberg.org/forgejo/forgejo/pulls/9099): <!--number 9099 --><!--line 0 --><!--description cHJldmVudCBpbml0aWFsICdibGFuaycgZGlzcGxheSBvZiBhY3Rpb24gbG9ncyB2aWV3LCByZW1vdmUgdW5uZWNlc3NhcnkgQVBJIGNhbGxz-->prevent initial 'blank' display of action logs view, remove unnecessary API calls<!--description--> <!--end release-notes-assistant--> Reviewed-on: https://codeberg.org/forgejo/forgejo/pulls/9099 Reviewed-by: Earl Warren <earl-warren@noreply.codeberg.org> Reviewed-by: Gusted <gusted@noreply.codeberg.org> Co-authored-by: Mathieu Fenniak <mathieu@fenniak.net> Co-committed-by: Mathieu Fenniak <mathieu@fenniak.net>
This commit is contained in:
parent
e0d6705b71
commit
a082555c04
6 changed files with 278 additions and 152 deletions
|
@ -14,6 +14,8 @@ const sfc = {
|
|||
ActionRunStatus,
|
||||
},
|
||||
props: {
|
||||
initialJobData: Object,
|
||||
initialArtifactData: Object,
|
||||
runIndex: String,
|
||||
runID: String,
|
||||
jobIndex: String,
|
||||
|
@ -96,10 +98,10 @@ const sfc = {
|
|||
},
|
||||
|
||||
async mounted() {
|
||||
// load job data and then auto-reload periodically
|
||||
// need to await first loadJob so this.currentJobStepsStates is initialized and can be used in hashChangeListener
|
||||
await this.loadJob();
|
||||
this.intervalID = setInterval(this.loadJob, 1000);
|
||||
// Need to await first loadJob so this.currentJobStepsStates is initialized and can be used in hashChangeListener,
|
||||
// but with the initializing data being passed in this should end up as a synchronous invocation. loadJob is
|
||||
// responsible for setting up its refresh interval during this first invocation.
|
||||
await this.loadJob({initialJobData: this.initialJobData, initialArtifactData: this.initialArtifactData});
|
||||
document.body.addEventListener('click', this.closeDropdown);
|
||||
this.hashChangeListener();
|
||||
window.addEventListener('hashchange', this.hashChangeListener);
|
||||
|
@ -312,7 +314,8 @@ const sfc = {
|
|||
return await resp.json();
|
||||
},
|
||||
|
||||
async loadJob() {
|
||||
async loadJob(initializationData) {
|
||||
const isInitializing = initializationData !== undefined;
|
||||
let myLoadingLogCursors = this.getLogCursors();
|
||||
if (this.loading) {
|
||||
// loadJob is already executing; but it's possible that our log cursor request has changed since it started. If
|
||||
|
@ -335,10 +338,18 @@ const sfc = {
|
|||
|
||||
while (true) {
|
||||
try {
|
||||
[job, artifacts] = await Promise.all([
|
||||
this.fetchJob(myLoadingLogCursors),
|
||||
this.fetchArtifacts(), // refresh artifacts if upload-artifact step done
|
||||
]);
|
||||
if (initializationData) {
|
||||
job = initializationData.initialJobData;
|
||||
artifacts = initializationData.initialArtifactData;
|
||||
// don't think it's possible that we loop retrying for 'needLoadingWithLogCursors' during initialization,
|
||||
// but just in case, we'll ensure initializationData can only be used once and go to the network on retry
|
||||
initializationData = undefined;
|
||||
} else {
|
||||
[job, artifacts] = await Promise.all([
|
||||
this.fetchJob(myLoadingLogCursors),
|
||||
this.fetchArtifacts(), // refresh artifacts if upload-artifact step done
|
||||
]);
|
||||
}
|
||||
} catch (err) {
|
||||
if (err instanceof TypeError) return; // avoid network error while unloading page
|
||||
throw err;
|
||||
|
@ -374,9 +385,14 @@ const sfc = {
|
|||
this.appendLogs(logs.step, logs.lines, logs.started);
|
||||
}
|
||||
|
||||
if (this.run.done && this.intervalID) {
|
||||
clearInterval(this.intervalID);
|
||||
this.intervalID = null;
|
||||
if (this.run.done) {
|
||||
if (this.intervalID) {
|
||||
clearInterval(this.intervalID);
|
||||
this.intervalID = null;
|
||||
}
|
||||
} else if (isInitializing) {
|
||||
// Begin refresh interval since we know this job isn't done.
|
||||
this.intervalID = setInterval(this.loadJob, 1000);
|
||||
}
|
||||
} finally {
|
||||
this.loading = false;
|
||||
|
@ -485,7 +501,12 @@ export function initRepositoryActionView() {
|
|||
const parentFullHeight = document.querySelector('body > div.full.height');
|
||||
if (parentFullHeight) parentFullHeight.style.paddingBottom = '0';
|
||||
|
||||
const initialJobData = JSON.parse(el.getAttribute('data-initial-post-response'));
|
||||
const initialArtifactData = JSON.parse(el.getAttribute('data-initial-artifacts-response'));
|
||||
|
||||
const view = createApp(sfc, {
|
||||
initialJobData,
|
||||
initialArtifactData,
|
||||
runIndex: el.getAttribute('data-run-index'),
|
||||
runID: el.getAttribute('data-run-id'),
|
||||
jobIndex: el.getAttribute('data-job-index'),
|
||||
|
@ -524,7 +545,7 @@ export function initRepositoryActionView() {
|
|||
}
|
||||
</script>
|
||||
<template>
|
||||
<div class="ui container fluid padded action-view-container">
|
||||
<div class="ui container fluid padded action-view-container" :class="{ 'interval-pending': intervalID }">
|
||||
<div class="action-view-header job-out-of-date-warning" v-if="!currentingViewingMostRecentAttempt">
|
||||
<div class="ui warning message">
|
||||
<!-- eslint-disable-next-line vue/no-v-html -->
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue