Skip to content

Commit

Permalink
Merge pull request #1125 from PrefectHQ/ui-performance/query-subscrip…
Browse files Browse the repository at this point in the history
…tions

Performance: More careful polling of graphql data
  • Loading branch information
zhen0 authored Dec 9, 2021
2 parents ee4b131 + b909fa2 commit 74e0580
Show file tree
Hide file tree
Showing 87 changed files with 659 additions and 111 deletions.
30 changes: 26 additions & 4 deletions src/App.vue
Original file line number Diff line number Diff line change
Expand Up @@ -91,6 +91,12 @@ export default {
'user',
'plan'
]),
...mapGetters('polling', [
'shouldPollTenants',
'shouldPollAgents',
'shouldPollProjects',
'shouldPollFlows'
]),
notFoundPage() {
return this.$route.name === 'not-found'
},
Expand Down Expand Up @@ -227,7 +233,11 @@ export default {
{
query: require('@/graphql/Tenant/tenants.js').default(this.isCloud),
skip() {
return (this.isCloud && !this.isAuthorized) || !this.connected
return (
(this.isCloud && !this.isAuthorized) ||
!this.connected ||
!this.shouldPollTenants
)
},
fetchPolicy: 'no-cache',
pollInterval: 60000,
Expand All @@ -244,7 +254,11 @@ export default {
return require('@/graphql/Agent/agents.js').default(this.isCloud)
},
skip() {
return (this.isCloud && !this.isAuthorized) || !this.connected
return (
(this.isCloud && !this.isAuthorized) ||
!this.connected ||
!this.shouldPollAgents
)
},
pollInterval: 1000,
// Without this, server UI with no actual server shows results
Expand All @@ -263,7 +277,11 @@ export default {
return require('@/graphql/Nav/projects.gql')
},
skip() {
return (this.isCloud && !this.isAuthorized) || !this.connected
return (
(this.isCloud && !this.isAuthorized) ||
!this.connected ||
!this.shouldPollProjects
)
},
pollInterval: 10000,
update(data) {
Expand All @@ -279,7 +297,11 @@ export default {
return require('@/graphql/Nav/flows.gql')
},
skip() {
return (this.isCloud && !this.isAuthorized) || !this.connected
return (
(this.isCloud && !this.isAuthorized) ||
!this.connected ||
!this.shouldPollFlows
)
},
pollInterval: 10000,
update(data) {
Expand Down
5 changes: 4 additions & 1 deletion src/components/Artifacts/Artifacts.vue
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,9 @@ export default {
},
increment() {
this.artifact++
},
onIntersect([entry]) {
this.$apollo.queries.artifacts.skip = !entry.isIntersecting
}
},
apollo: {
Expand Down Expand Up @@ -80,7 +83,7 @@ export default {
</script>
<template>
<v-row no-gutters>
<v-row v-intersect="{ handler: onIntersect }" no-gutters>
<v-col>
<div
v-if="artifacts && artifacts.length > 0"
Expand Down
7 changes: 6 additions & 1 deletion src/components/ConcurrencyInfo.vue
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,11 @@ export default {
return this.license?.terms?.flow_concurrency
}
},
methods: {
onIntersect([entry]) {
this.$apollo.queries.concurrentRuns.skip = !entry.isIntersecting
}
},
apollo: {
concurrentRuns: {
query: require('@/graphql/concurrent-runs.gql'),
Expand All @@ -28,7 +33,7 @@ export default {
</script>
<template>
<div v-if="concurrentRuns && license">
<div v-if="concurrentRuns && license" v-intersect="{ handler: onIntersect }">
{{ concurrentRuns.length
}}{{ flowConcurrency ? `/${flowConcurrency}` : '' }} slot{{
concurrentRuns.length === 1 || flowConcurrency === 1 ? '' : 's'
Expand Down
16 changes: 15 additions & 1 deletion src/components/LabelWarning.vue
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,9 @@ export default {
data() {
return {
infoMessage: '',
noLabelInfo: false
noLabelInfo: false,
unsubscribeAgents: null,
show: false
}
},
computed: {
Expand Down Expand Up @@ -102,6 +104,16 @@ export default {
methods: {
labelMessage(message) {
this.infoMessage = message
},
async visibilityChanged(visible) {
if (visible) {
this.unsubscribeAgents = await this.$store.dispatch(
'polling/subscribe',
'agents'
)
} else {
this.unsubscribeAgents()
}
}
}
}
Expand All @@ -110,9 +122,11 @@ export default {
<template>
<v-menu
v-if="!labelsAlign"
v-model="show"
:close-on-content-click="false"
offset-y
open-on-hover
@input="visibilityChanged"
>
<template #activator="{ on }">
<div text class="super-imposed-icon-set cursor-pointer" v-on="on">
Expand Down
4 changes: 4 additions & 0 deletions src/components/LastTenRuns.vue
Original file line number Diff line number Diff line change
Expand Up @@ -151,6 +151,9 @@ export default {
height: '1rem',
width: '1rem'
}
},
onIntersect([entry]) {
this.$apollo.queries.flowRuns.skip = !entry.isIntersecting
}
},
apollo: {
Expand All @@ -174,6 +177,7 @@ export default {
<template>
<div>
<BarChart
v-intersect="{ handler: onIntersect }"
:items="preppedFlowRuns"
:loading="loadingKey > 0"
:height="50"
Expand Down
7 changes: 6 additions & 1 deletion src/components/LogsCard/LogsCard.vue
Original file line number Diff line number Diff line change
Expand Up @@ -192,6 +192,11 @@ export default {
if (!this.logsQueryResultsTarget || !this.logsQueryResults) return
this.scopeLogs()
},
onIntersect([entry]) {
this.$apollo.queries.logsQueryResults.skip = !entry.isIntersecting
this.$apollo.queries.logsQueryResultsOlder.skip = !entry.isIntersecting
this.$apollo.queries.logsQueryResultsNewer.skip = !entry.isIntersecting
}
},
created() {
Expand Down Expand Up @@ -513,7 +518,7 @@ export default {
</script>
<template>
<div data-private>
<div v-intersect="{ handler: onIntersect }" data-private>
<v-card class="logs-card" tile>
<v-system-bar :color="entityState" :height="5" absolute>
<!-- We should include a state icon here when we've got those -->
Expand Down
6 changes: 6 additions & 0 deletions src/components/Nav/NotificationMenu.vue
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,11 @@ export default {
return this.notificationsCount
}
},
methods: {
onIntersect([entry]) {
this.$apollo.queries.notificationsCount.skip = !entry.isIntersecting
}
},
apollo: {
notificationsCount: {
query: require('@/graphql/Notifications/notifications-count-unread.gql'),
Expand All @@ -27,6 +32,7 @@ export default {
<template>
<v-btn
v-intersect="{ handler: onIntersect }"
:to="'/notifications'"
class="navbar-icon mx-1"
icon
Expand Down
37 changes: 20 additions & 17 deletions src/components/Nav/TeamSideNav.vue
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,6 @@ export default {
},
data() {
return {
activateTimeout: null,
items: [],
newProjectDialog: false,
types: {
Expand All @@ -25,8 +24,9 @@ export default {
flow: 'pi-flow',
task: 'pi-task'
},
flowsUnWatch: null,
projectsUnWatch: null
unwatchFlows: null,
unwatchProjects: null,
unsubscribeData: null
}
},
Expand Down Expand Up @@ -80,20 +80,20 @@ export default {
}
},
watch: {
isOpen(val) {
async isOpen(val) {
if (val) {
clearTimeout(this.activateTimeout)
this.activateTimeout = setTimeout(() => {
this.$refs['drawer'].focus()
}, 250)
this.flowsUnWatch = this.$watch('flows', this.updateItems)
this.projectsUnWatch = this.$watch('projects', this.updateItems)
this.updateItems()
this.unwatchFlows = this.$watch('flows', this.updateItems)
this.unwatchProjects = this.$watch('projects', this.updateItems)
this.unsubscribeData = await this.$store.dispatch('polling/subscribe', [
'flows',
'projects'
])
} else {
this.flowsUnWatch()
this.projectsUnWatch()
this.unwatchFlows()
this.unwatchProjects()
this.unsubscribeData()
}
}
},
Expand All @@ -107,12 +107,15 @@ export default {
// Removes the t search shortcut event listener when
// the component is destroyed
window.removeEventListener('keyup', this.handleKeyboardShortcut)
clearTimeout(this.activateTimeout)
},
methods: {
...mapMutations('sideNav', ['close', 'open']),
...mapMutations('data', ['addTasks']),
onIntersect([entry]) {
if (entry.isIntersecting) {
entry.target.focus()
}
},
closeAll() {
this.$refs['tree'].close()
},
Expand Down Expand Up @@ -273,7 +276,7 @@ export default {
</div>
<div
ref="drawer"
v-intersect="{ handler: onIntersect }"
class="focusable tree-view flex-grow-1 flex-shrink-1"
tabindex="-1"
>
Expand Down
3 changes: 2 additions & 1 deletion src/components/Nav/TeamSwitcher.vue
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
<script>
import { mapActions, mapGetters } from 'vuex'
import { handleMembershipInvitations } from '@/mixins/membershipInvitationMixin'
import { pollsTenantsMixin } from '@/mixins/polling/pollsTenantsMixin'
import AcceptConfirmInputRow from '@/components/AcceptConfirmInputRow'
import { clearCache } from '@/vue-apollo'
Expand Down Expand Up @@ -37,7 +38,7 @@ const tenantProtectedRoutes = [
export default {
components: { AcceptConfirmInputRow },
mixins: [handleMembershipInvitations],
mixins: [handleMembershipInvitations, pollsTenantsMixin],
data() {
return {
loading: false,
Expand Down
8 changes: 7 additions & 1 deletion src/components/Schematics/Preview-Dynamic.vue
Original file line number Diff line number Diff line change
Expand Up @@ -59,6 +59,9 @@ export default {
: ['white--text']
return [state, ...textColor]
},
onIntersect([entry]) {
this.$apollo.queries.mappedChildren.skip = !entry.isIntersecting
}
},
apollo: {
Expand All @@ -80,7 +83,10 @@ export default {
</script>
<template>
<v-card-text class="full-height position-relative pa-0 text-caption">
<v-card-text
v-intersect="{ handler: onIntersect }"
class="full-height position-relative pa-0 text-caption"
>
<v-list-item
class="py-2 pr-2 pl-3"
dense
Expand Down
4 changes: 4 additions & 0 deletions src/components/Schematics/Schematic-Node.vue
Original file line number Diff line number Diff line change
Expand Up @@ -158,6 +158,9 @@ export default {
},
isFinished(state) {
return FINISHED_STATES.includes(state)
},
onIntersect([entry]) {
this.$apollo.queries.mappedChildren.skip = !entry.isIntersecting
}
},
apollo: {
Expand All @@ -183,6 +186,7 @@ export default {
<template>
<div
v-intersect="{ handler: onIntersect }"
v-ripple
class="utilGrayLight d-flex align-center node ripple"
:class="showDetails ? 'elevation-3' : ''"
Expand Down
7 changes: 6 additions & 1 deletion src/components/SetStateDialog.vue
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,11 @@ export default {
return !this.hasPermission('update', 'run')
}
},
methods: {
onIntersect([entry]) {
this.$apollo.queries.taskRunIds.skip = !entry.isIntersecting
}
},
apollo: {
taskRunIds: {
query: require('@/graphql/FlowRun/task-run-ids.gql'),
Expand All @@ -36,7 +41,7 @@ export default {
</script>

<template>
<div v-if="activeButton">
<div v-if="activeButton" v-intersect="{ handler: onIntersect }">
<v-dialog v-model="setStateDialog" max-width="600" @click:outside="reset">
<template #activator="{ on: dialog }">
<v-tooltip bottom>
Expand Down
Loading

0 comments on commit 74e0580

Please sign in to comment.