Skip to content
Draft
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 5 additions & 0 deletions routers/web/repo/actions/actions.go
Original file line number Diff line number Diff line change
Expand Up @@ -119,6 +119,11 @@ func List(ctx *context.Context) {
return
}

if ctx.FormBool("runs-list-only") {

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The runs-list-only short-circuit is placed after every prepare* call. So every 3s (per open tab, per client, forever) the server re-runs prepareWorkflowTemplate → actions.ListWorkflows (git tree read) → reads and YAML-parses every workflow file → ResolveUses for reusable workflows (actions.go:188-227), plus the scoped/other/dispatch prep — all of it discarded, only runs_list returned. On a repo with many/large workflow files this is a large, continuous CPU + git-I/O cost for a "lightweight" refresh.

ctx.HTML(http.StatusOK, "repo/actions/runs_list")
return
}

ctx.HTML(http.StatusOK, tplListActions)
}

Expand Down
2 changes: 1 addition & 1 deletion templates/repo/actions/list.tmpl
Original file line number Diff line number Diff line change
Expand Up @@ -152,7 +152,7 @@
{{template "repo/actions/workflow_dispatch" .}}
{{end}}

<div class="ui attached segment">
<div class="ui attached segment" id="actions-runs-list">
{{template "repo/actions/runs_list" .}}
</div>
</div>
Expand Down
2 changes: 1 addition & 1 deletion templates/repo/actions/runs_list.tmpl
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
</div>
{{end}}
{{range $run := .Runs}}
<div class="item tw-items-center">
<div class="item tw-items-center" data-status="{{$run.Status.String}}">
<div class="item-leading">
<span data-tooltip-content="{{ctx.Locale.Tr (printf "actions.status.%s" $run.Status.String)}}">
{{template "repo/icons/action_status" (dict "Status" $run.Status.String "IconVariant" "circle-fill")}}
Expand Down
53 changes: 53 additions & 0 deletions web_src/js/features/repo-actions.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,9 @@
import {createApp} from 'vue';
import {Idiomorph} from 'idiomorph';
import RepoActionView from '../components/RepoActionView.vue';
import {registerGlobalInitFunc} from '../modules/observer.ts';
import {html} from '../utils/html.ts';
import {GET} from '../modules/fetch.ts';

export function updateWorkflowBadgeFields(form: HTMLElement, branch: string): void {
const badgeURLParsed = new URL(form.getAttribute('data-badge-url')!);
Expand All @@ -27,6 +29,7 @@ function initWorkflowBadgeForm(form: HTMLElement): void {
export function initRepositoryActions() {
registerGlobalInitFunc('initWorkflowBadgeForm', initWorkflowBadgeForm);
initRepositoryActionsView();
initRepositoryActionsList();
}

function initRepositoryActionsView() {
Expand Down Expand Up @@ -103,3 +106,53 @@ function initRepositoryActionsView() {
});
view.mount(el);
}

function initRepositoryActionsList(): void {
const runsList = document.querySelector('#actions-runs-list');
if (!runsList) return;

let timerId: number | null = null;
let pollingInterval = 3000;

const runPolling = async () => {
if (!document.contains(runsList)) {
if (timerId) {
clearTimeout(timerId);
}
return;
}

if (document.hidden) {
timerId = window.setTimeout(runPolling, pollingInterval);
return;
}

const hasActiveRuns = document.querySelector(
Comment thread
wxiaoguang marked this conversation as resolved.
Outdated
'#actions-runs-list .run-list .item[data-status="running"], ' +
'#actions-runs-list .run-list .item[data-status="waiting"], ' +
'#actions-runs-list .run-list .item[data-status="cancelling"]',
Comment thread
wxiaoguang marked this conversation as resolved.
Outdated
) !== null;

pollingInterval = hasActiveRuns ? 3000 : 10000;

try {
const url = new URL(window.location.href);

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

open run action-menu (kebab dropdown) is reset on every morph.

url.searchParams.set('runs-list-only', 'true');
const response = await GET(url.href, {
headers: {
'X-Requested-With': 'XMLHttpRequest',
Comment thread
wxiaoguang marked this conversation as resolved.
Outdated
},
});
if (response.ok) {
const htmlText = await response.text();
Idiomorph.morph(runsList, htmlText, {morphStyle: 'innerHTML'});
}
} catch (e) {
console.error('Failed to update actions runs list:', e);
}

timerId = window.setTimeout(runPolling, pollingInterval);
};

timerId = window.setTimeout(runPolling, pollingInterval);
}
Loading