Skip to content

Commit

Permalink
[wip] test slow updates
Browse files Browse the repository at this point in the history
[skip ci]

Signed-off-by: Maksim Sukharev <[email protected]>
  • Loading branch information
Antreesy committed Jun 21, 2024
1 parent 1abf47b commit 1220066
Showing 1 changed file with 7 additions and 11 deletions.
18 changes: 7 additions & 11 deletions src/composables/useGetParticipants.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,13 +3,12 @@
* SPDX-License-Identifier: AGPL-3.0-or-later
*/
import debounce from 'debounce'
import { ref, nextTick, computed, watch, onBeforeUnmount, onMounted } from 'vue'
import { ref, computed, watch, onBeforeUnmount, onMounted } from 'vue'

import { subscribe, unsubscribe } from '@nextcloud/event-bus'

import { useIsInCall } from './useIsInCall.js'
import { useStore } from './useStore.js'
import { CONVERSATION } from '../constants.js'
import { EventBus } from '../services/EventBus.js'

/**
Expand All @@ -23,8 +22,6 @@ export function useGetParticipants(isActive = ref(true), isTopBar = true) {
const token = computed(() => store.getters.getToken())
const conversation = computed(() => store.getters.conversation(token.value))
const isInCall = useIsInCall()
const isOneToOneConversation = computed(() => conversation.value?.type === CONVERSATION.TYPE.ONE_TO_ONE
|| conversation.value?.type === CONVERSATION.TYPE.ONE_TO_ONE_FORMER)
let fetchingParticipants = false
let pendingChanges = true

Expand Down Expand Up @@ -83,11 +80,7 @@ export function useGetParticipants(isActive = ref(true), isTopBar = true) {
}

const onJoinedConversation = () => {
if (isOneToOneConversation.value) {
cancelableGetParticipants()
} else {
nextTick(() => debounceUpdateParticipants())
}
cancelableGetParticipants()
}

const debounceUpdateParticipants = () => {
Expand All @@ -98,14 +91,17 @@ export function useGetParticipants(isActive = ref(true), isTopBar = true) {
}

if (store.getters.windowIsVisible() && (isInCall.value || !conversation.value?.hasCall)) {
console.log('perf: debounceFastUpdateParticipants')
debounceFastUpdateParticipants()
} else {
console.log('perf: debounceSlowUpdateParticipants')
debounceSlowUpdateParticipants()
}
pendingChanges = false
}

const cancelableGetParticipants = async () => {
console.log('perf: cancelableGetParticipants')
const isInLobby = store.getters.isInLobby
const isModeratorOrUser = store.getters.isModeratorOrUser
if (fetchingParticipants || token.value === '' || isInLobby || !isModeratorOrUser) {
Expand All @@ -121,9 +117,9 @@ export function useGetParticipants(isActive = ref(true), isTopBar = true) {
}

const debounceFastUpdateParticipants = debounce(
cancelableGetParticipants, 3000)
const debounceSlowUpdateParticipants = debounce(
cancelableGetParticipants, 15000)
const debounceSlowUpdateParticipants = debounce(
cancelableGetParticipants, 30000)

onMounted(() => {
if (isTopBar) {
Expand Down

0 comments on commit 1220066

Please sign in to comment.