Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix: Improve executions list polling performance #6355

Merged
merged 6 commits into from
Jun 1, 2023
Merged
Show file tree
Hide file tree
Changes from 4 commits
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
13 changes: 7 additions & 6 deletions packages/editor-ui/src/components/ExecutionsList.vue
Original file line number Diff line number Diff line change
Expand Up @@ -327,7 +327,7 @@ export default defineComponent({
allVisibleSelected: false,
allExistingSelected: false,
autoRefresh: true,
autoRefreshInterval: undefined as undefined | NodeJS.Timer,
autoRefreshTimeout: undefined as undefined | NodeJS.Timer,

filter: {} as ExecutionFilterType,

Expand Down Expand Up @@ -919,15 +919,16 @@ export default defineComponent({
this.selectAllVisibleExecutions();
}
},
startAutoRefreshInterval() {
async startAutoRefreshInterval() {
if (this.autoRefresh) {
this.autoRefreshInterval = setInterval(() => this.loadAutoRefresh(), 4 * 1000); // refresh data every 4 secs
await this.loadAutoRefresh();
this.autoRefreshTimeout = setTimeout(() => this.startAutoRefreshInterval(), 4 * 1000); // refresh data every 4 secs
}
},
stopAutoRefreshInterval() {
if (this.autoRefreshInterval) {
clearInterval(this.autoRefreshInterval);
this.autoRefreshInterval = undefined;
if (this.autoRefreshTimeout) {
clearTimeout(this.autoRefreshTimeout);
this.autoRefreshTimeout = undefined;
}
},
onDocumentVisibilityChange() {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,11 +5,12 @@
:loading="loading && !executions.length"
:loadingMore="loadingMore"
:temporaryExecution="temporaryExecution"
:auto-refresh="autoRefresh"
@update:autoRefresh="onAutoRefreshToggle"
@reloadExecutions="setExecutions"
@filterUpdated="onFilterUpdated"
@loadMore="onLoadMore"
@retryExecution="onRetryExecution"
@refresh="loadAutoRefresh"
/>
<div :class="$style.content" v-if="!hidePreview">
<router-view
Expand Down Expand Up @@ -83,6 +84,8 @@ export default defineComponent({
loadingMore: false,
filter: {} as ExecutionFilterType,
temporaryExecution: null as IExecutionsSummary | null,
autoRefresh: false,
autoRefreshTimeout: undefined as undefined | NodeJS.Timer,
};
},
setup() {
Expand Down Expand Up @@ -187,8 +190,17 @@ export default defineComponent({
await this.setExecutions();
}
}

this.autoRefresh = this.uiStore.executionSidebarAutoRefresh === true;
this.startAutoRefreshInterval();
document.addEventListener('visibilitychange', this.onDocumentVisibilityChange);

this.loading = false;
},
beforeDestroy() {
this.stopAutoRefreshInterval();
document.removeEventListener('visibilitychange', this.onDocumentVisibilityChange);
},
methods: {
async initView(loadWorkflow: boolean): Promise<void> {
if (loadWorkflow) {
Expand Down Expand Up @@ -325,14 +337,41 @@ export default defineComponent({
);
}
},
async onFilterUpdated(filter: ExecutionFilterType): void {
async onFilterUpdated(filter: ExecutionFilterType) {
this.filter = filter;
await this.setExecutions();
},
async setExecutions(): Promise<void> {
this.workflowsStore.currentWorkflowExecutions = await this.loadExecutions();
await this.setActiveExecution();
},

async startAutoRefreshInterval() {
if (this.autoRefresh) {
await this.loadAutoRefresh();
this.autoRefreshTimeout = setTimeout(() => this.startAutoRefreshInterval(), 4000);
}
},
stopAutoRefreshInterval() {
if (this.autoRefreshTimeout) {
clearTimeout(this.autoRefreshTimeout);
this.autoRefreshTimeout = undefined;
}
},
onAutoRefreshToggle(value: boolean): void {
this.autoRefresh = value;
this.uiStore.executionSidebarAutoRefresh = this.autoRefresh;

this.stopAutoRefreshInterval(); // Clear any previously existing intervals (if any - there shouldn't)
this.startAutoRefreshInterval();
},
onDocumentVisibilityChange() {
if (document.visibilityState === 'hidden') {
this.stopAutoRefreshInterval();
} else {
this.startAutoRefreshInterval();
}
},
async loadAutoRefresh(): Promise<void> {
// Most of the auto-refresh logic is taken from the `ExecutionsList` component
const fetchedExecutions: IExecutionsSummary[] = await this.loadExecutions();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,8 +11,8 @@
</div>
<div :class="$style.controls">
<el-checkbox
v-model="autoRefresh"
@change="onAutoRefreshToggle"
:value="autoRefresh"
@input="$emit('update:autoRefresh', $event)"
data-test-id="auto-refresh-checkbox"
>
{{ $locale.baseText('executionsList.autoRefresh') }}
Expand All @@ -39,7 +39,6 @@
:ref="`execution-${temporaryExecution.id}`"
:data-test-id="`execution-details-${temporaryExecution.id}`"
:showGap="true"
@refresh="onRefresh"
@retryExecution="onRetryExecution"
/>
<execution-card
Expand All @@ -48,7 +47,6 @@
:execution="execution"
:ref="`execution-${execution.id}`"
:data-test-id="`execution-details-${execution.id}`"
@refresh="onRefresh"
@retryExecution="onRetryExecution"
/>
<div v-if="loadingMore" class="mr-m">
Expand Down Expand Up @@ -85,6 +83,10 @@ export default defineComponent({
ExecutionFilter,
},
props: {
autoRefresh: {
type: Boolean,
default: false,
},
executions: {
type: Array as PropType<IExecutionsSummary[]>,
required: true,
Expand All @@ -106,8 +108,6 @@ export default defineComponent({
return {
VIEWS,
filter: {} as ExecutionFilterType,
autoRefresh: false,
autoRefreshInterval: undefined as undefined | NodeJS.Timer,
};
},
computed: {
Expand All @@ -126,39 +126,12 @@ export default defineComponent({
},
},
mounted() {
this.autoRefresh = this.uiStore.executionSidebarAutoRefresh === true;
this.startAutoRefreshInterval();

// On larger screens, we need to load more then first page of executions
// for the scroll bar to appear and infinite scrolling is enabled
this.checkListSize();
this.scrollToActiveCard();

document.addEventListener('visibilitychange', this.onDocumentVisibilityChange);
},
beforeDestroy() {
this.stopAutoRefreshInterval();
document.removeEventListener('visibilitychange', this.onDocumentVisibilityChange);
},
methods: {
startAutoRefreshInterval() {
if (this.autoRefresh) {
this.autoRefreshInterval = setInterval(() => this.onRefresh(), 4000);
}
},
stopAutoRefreshInterval() {
if (this.autoRefreshInterval) {
clearInterval(this.autoRefreshInterval);
this.autoRefreshInterval = undefined;
}
},
onDocumentVisibilityChange() {
if (document.visibilityState === 'hidden') {
this.stopAutoRefreshInterval();
} else {
this.startAutoRefreshInterval();
}
},
loadMore(limit = 20): void {
if (!this.loading) {
const executionsListRef = this.$refs.executionList as HTMLElement | undefined;
Expand All @@ -184,12 +157,6 @@ export default defineComponent({
reloadExecutions(): void {
this.$emit('reloadExecutions');
},
onAutoRefreshToggle(): void {
this.uiStore.executionSidebarAutoRefresh = this.autoRefresh;

this.stopAutoRefreshInterval(); // Clear any previously existing intervals (if any - there shouldn't)
this.startAutoRefreshInterval();
},
checkListSize(): void {
const sidebarContainerRef = this.$refs.container as HTMLElement | undefined;
const currentExecutionCardRefs = this.$refs[
Expand Down