mirror of
https://github.com/elk-zone/elk.git
synced 2024-09-06 12:19:08 +01:00
fix: Streams slowing down page loads or not loading at all (#620)
This commit is contained in:
parent
e9b1f17235
commit
b6f0bd356a
12 changed files with 62 additions and 47 deletions
|
@ -15,7 +15,7 @@ const {
|
||||||
paginator: Paginator<any, any[]>
|
paginator: Paginator<any, any[]>
|
||||||
keyProp?: string
|
keyProp?: string
|
||||||
virtualScroller?: boolean
|
virtualScroller?: boolean
|
||||||
stream?: WsEvents
|
stream?: Promise<WsEvents>
|
||||||
eventType?: 'notification' | 'update'
|
eventType?: 'notification' | 'update'
|
||||||
preprocess?: (items: any[]) => any[]
|
preprocess?: (items: any[]) => any[]
|
||||||
}>()
|
}>()
|
||||||
|
|
|
@ -4,7 +4,7 @@ import type { GroupedAccountLike, NotificationSlot } from '~/types'
|
||||||
|
|
||||||
const { paginator, stream } = defineProps<{
|
const { paginator, stream } = defineProps<{
|
||||||
paginator: Paginator<any, Notification[]>
|
paginator: Paginator<any, Notification[]>
|
||||||
stream?: WsEvents
|
stream?: Promise<WsEvents>
|
||||||
}>()
|
}>()
|
||||||
|
|
||||||
const groupCapacity = Number.MAX_VALUE // No limit
|
const groupCapacity = Number.MAX_VALUE // No limit
|
||||||
|
|
|
@ -1,8 +1,8 @@
|
||||||
<script setup lang="ts">
|
<script setup lang="ts">
|
||||||
import type { Status } from 'masto'
|
import type { Status } from 'masto'
|
||||||
const paginator = useMasto().timelines.iterateHome()
|
const paginator = useMasto().timelines.iterateHome()
|
||||||
const stream = await useMasto().stream.streamUser()
|
const stream = useMasto().stream.streamUser()
|
||||||
onBeforeUnmount(() => stream.disconnect())
|
onBeforeUnmount(() => stream?.then(s => s.disconnect()))
|
||||||
|
|
||||||
const maxDistance = 10
|
const maxDistance = 10
|
||||||
function preprocess(items: Status[]) {
|
function preprocess(items: Status[]) {
|
||||||
|
|
|
@ -5,7 +5,7 @@ const paginator = useMasto().notifications.iterate({ limit: 30, types: ['mention
|
||||||
const { clearNotifications } = useNotifications()
|
const { clearNotifications } = useNotifications()
|
||||||
onActivated(clearNotifications)
|
onActivated(clearNotifications)
|
||||||
|
|
||||||
const stream = await useMasto().stream.streamUser()
|
const stream = useMasto().stream.streamUser()
|
||||||
</script>
|
</script>
|
||||||
|
|
||||||
<template>
|
<template>
|
||||||
|
|
|
@ -5,7 +5,7 @@ const paginator = useMasto().notifications.iterate({ limit: 30 })
|
||||||
const { clearNotifications } = useNotifications()
|
const { clearNotifications } = useNotifications()
|
||||||
onActivated(clearNotifications)
|
onActivated(clearNotifications)
|
||||||
|
|
||||||
const stream = await useMasto().stream.streamUser()
|
const stream = useMasto().stream.streamUser()
|
||||||
</script>
|
</script>
|
||||||
|
|
||||||
<template>
|
<template>
|
||||||
|
|
|
@ -6,7 +6,7 @@ import type { FilterContext, Paginator, Status, WsEvents } from 'masto'
|
||||||
|
|
||||||
const { paginator, stream } = defineProps<{
|
const { paginator, stream } = defineProps<{
|
||||||
paginator: Paginator<any, Status[]>
|
paginator: Paginator<any, Status[]>
|
||||||
stream?: WsEvents
|
stream?: Promise<WsEvents>
|
||||||
context?: FilterContext
|
context?: FilterContext
|
||||||
preprocess?: (items: any[]) => any[]
|
preprocess?: (items: any[]) => any[]
|
||||||
}>()
|
}>()
|
||||||
|
|
11
components/timeline/TimelinePublic.vue
Normal file
11
components/timeline/TimelinePublic.vue
Normal file
|
@ -0,0 +1,11 @@
|
||||||
|
<script setup lang="ts">
|
||||||
|
const paginator = useMasto().timelines.iteratePublic()
|
||||||
|
const stream = useMasto().stream.streamPublicTimeline()
|
||||||
|
onBeforeUnmount(() => stream.then(s => s.disconnect()))
|
||||||
|
</script>
|
||||||
|
|
||||||
|
<template>
|
||||||
|
<div>
|
||||||
|
<TimelinePaginator v-bind="{ paginator, stream }" context="public" />
|
||||||
|
</div>
|
||||||
|
</template>
|
11
components/timeline/TimelinePublicLocal.vue
Normal file
11
components/timeline/TimelinePublicLocal.vue
Normal file
|
@ -0,0 +1,11 @@
|
||||||
|
<script setup lang="ts">
|
||||||
|
const paginator = useMasto().timelines.iteratePublic({ local: true })
|
||||||
|
const stream = useMasto().stream.streamCommunityTimeline()
|
||||||
|
onBeforeUnmount(() => stream.then(s => s.disconnect()))
|
||||||
|
</script>
|
||||||
|
|
||||||
|
<template>
|
||||||
|
<div>
|
||||||
|
<TimelinePaginator v-bind="{ paginator, stream }" context="public" />
|
||||||
|
</div>
|
||||||
|
</template>
|
|
@ -4,7 +4,7 @@ import type { PaginatorState } from '~/types'
|
||||||
|
|
||||||
export function usePaginator<T>(
|
export function usePaginator<T>(
|
||||||
paginator: Paginator<any, T[]>,
|
paginator: Paginator<any, T[]>,
|
||||||
stream?: WsEvents,
|
stream?: Promise<WsEvents>,
|
||||||
eventType: 'notification' | 'update' = 'update',
|
eventType: 'notification' | 'update' = 'update',
|
||||||
preprocess: (items: T[]) => T[] = (items: T[]) => items,
|
preprocess: (items: T[]) => T[] = (items: T[]) => items,
|
||||||
) {
|
) {
|
||||||
|
@ -24,7 +24,8 @@ export function usePaginator<T>(
|
||||||
prevItems.value = []
|
prevItems.value = []
|
||||||
}
|
}
|
||||||
|
|
||||||
stream?.on(eventType, (status) => {
|
stream?.then((s) => {
|
||||||
|
s.on(eventType, (status) => {
|
||||||
if ('uri' in status)
|
if ('uri' in status)
|
||||||
cacheStatus(status, undefined, true)
|
cacheStatus(status, undefined, true)
|
||||||
|
|
||||||
|
@ -36,7 +37,7 @@ export function usePaginator<T>(
|
||||||
})
|
})
|
||||||
|
|
||||||
// TODO: update statuses
|
// TODO: update statuses
|
||||||
stream?.on('status.update', (status) => {
|
s.on('status.update', (status) => {
|
||||||
cacheStatus(status, undefined, true)
|
cacheStatus(status, undefined, true)
|
||||||
|
|
||||||
const index = items.value.findIndex((s: any) => s.id === status.id)
|
const index = items.value.findIndex((s: any) => s.id === status.id)
|
||||||
|
@ -44,13 +45,14 @@ export function usePaginator<T>(
|
||||||
items.value[index] = status as any
|
items.value[index] = status as any
|
||||||
})
|
})
|
||||||
|
|
||||||
stream?.on('delete', (id) => {
|
s.on('delete', (id) => {
|
||||||
removeCachedStatus(id)
|
removeCachedStatus(id)
|
||||||
|
|
||||||
const index = items.value.findIndex((s: any) => s.id === id)
|
const index = items.value.findIndex((s: any) => s.id === id)
|
||||||
if (index >= 0)
|
if (index >= 0)
|
||||||
items.value.splice(index, 1)
|
items.value.splice(index, 1)
|
||||||
})
|
})
|
||||||
|
})
|
||||||
|
|
||||||
async function loadNext() {
|
async function loadNext() {
|
||||||
if (state.value !== 'idle')
|
if (state.value !== 'idle')
|
||||||
|
|
|
@ -1,7 +1,5 @@
|
||||||
<script setup lang="ts">
|
<script setup lang="ts">
|
||||||
const paginator = useMasto().timelines.iteratePublic()
|
|
||||||
const stream = await useMasto().stream.streamPublicTimeline()
|
|
||||||
onBeforeUnmount(() => stream.disconnect())
|
|
||||||
|
|
||||||
const { t } = useI18n()
|
const { t } = useI18n()
|
||||||
|
|
||||||
|
@ -19,8 +17,6 @@ useHeadFixed({
|
||||||
</NuxtLink>
|
</NuxtLink>
|
||||||
</template>
|
</template>
|
||||||
|
|
||||||
<slot>
|
<TimelinePublic v-if="isMastoInitialised" />
|
||||||
<TimelinePaginator v-bind="{ paginator, stream }" context="public" />
|
|
||||||
</slot>
|
|
||||||
</MainContent>
|
</MainContent>
|
||||||
</template>
|
</template>
|
||||||
|
|
|
@ -1,7 +1,4 @@
|
||||||
<script setup lang="ts">
|
<script setup lang="ts">
|
||||||
const paginator = useMasto().timelines.iteratePublic({ local: true })
|
|
||||||
const stream = await useMasto().stream.streamCommunityTimeline()
|
|
||||||
onBeforeUnmount(() => stream.disconnect())
|
|
||||||
|
|
||||||
const { t } = useI18n()
|
const { t } = useI18n()
|
||||||
|
|
||||||
|
@ -19,8 +16,6 @@ useHeadFixed({
|
||||||
</NuxtLink>
|
</NuxtLink>
|
||||||
</template>
|
</template>
|
||||||
|
|
||||||
<slot>
|
<TimelinePublicLocal v-if="isMastoInitialised" />
|
||||||
<TimelinePaginator v-bind="{ paginator, stream }" context="public" />
|
|
||||||
</slot>
|
|
||||||
</MainContent>
|
</MainContent>
|
||||||
</template>
|
</template>
|
||||||
|
|
|
@ -6,8 +6,8 @@ const masto = useMasto()
|
||||||
const { data: tag, refresh } = $(await useAsyncData(() => masto.tags.fetch(tagName), { watch: [isMastoInitialised], immediate: isMastoInitialised.value }))
|
const { data: tag, refresh } = $(await useAsyncData(() => masto.tags.fetch(tagName), { watch: [isMastoInitialised], immediate: isMastoInitialised.value }))
|
||||||
|
|
||||||
const paginator = masto.timelines.iterateHashtag(tagName)
|
const paginator = masto.timelines.iterateHashtag(tagName)
|
||||||
const stream = await masto.stream.streamTagTimeline(tagName)
|
const stream = masto.stream.streamTagTimeline(tagName)
|
||||||
onBeforeUnmount(() => stream.disconnect())
|
onBeforeUnmount(() => stream.then(s => s.disconnect()))
|
||||||
|
|
||||||
if (tag) {
|
if (tag) {
|
||||||
useHeadFixed({
|
useHeadFixed({
|
||||||
|
|
Loading…
Reference in a new issue