perf(files): only emit initialization once

Signed-off-by: Ferdinand Thiessen <opensource@fthiessen.de>
This commit is contained in:
Ferdinand Thiessen 2026-02-11 23:29:14 +01:00
parent 69f2c17675
commit e5c1d80a00
No known key found for this signature in database
GPG key ID: 7E849AE05218500F
3 changed files with 17 additions and 14 deletions

View file

@ -12,6 +12,8 @@ declare module '@nextcloud/event-bus' {
'files:config:updated': { key: string, value: UserConfig[string] }
'files:view-config:updated': { key: string, value: string | number | boolean, IView: string }
'files:list:initialized': undefined
'files:favorites:added': INode
'files:favorites:removed': INode

View file

@ -10,10 +10,8 @@ import { subscribe } from '@nextcloud/event-bus'
import { Folder, getNavigation, Permission } from '@nextcloud/files'
import { getRemoteURL, getRootPath } from '@nextcloud/files/dav'
import { defineStore } from 'pinia'
import { computed, ref, shallowRef, watch } from 'vue'
import { useRouteParameters } from '../composables/useRouteParameters.ts'
import { ref, shallowRef, watch } from 'vue'
import logger from '../logger.ts'
import { useFilesStore } from './files.ts'
// Temporary fake folder to use until we have the first valid folder
// fetched and cached. This allow us to mount the FilesListVirtual
@ -42,19 +40,10 @@ export const useActiveStore = defineStore('active', () => {
*/
const activeView = shallowRef<IView>()
const filesStore = useFilesStore()
const { directory } = useRouteParameters()
/**
* The currently active folder
*/
const activeFolder = computed<IFolder>(() => {
if (!activeView.value?.id) {
return dummyFolder
}
return filesStore.getDirectoryByPath(activeView.value.id, directory.value)
?? dummyFolder
})
const activeFolder = ref<IFolder>(dummyFolder)
// Set the active node on the router params
watch(activeNode, () => {

View file

@ -170,7 +170,7 @@ import { ShareType } from '@nextcloud/sharing'
import { UploadPicker, UploadStatus } from '@nextcloud/upload'
import { useThrottleFn } from '@vueuse/core'
import { normalize, relative } from 'path'
import { computed, defineComponent } from 'vue'
import { computed, defineComponent, nextTick, watch } from 'vue'
import Teleport from 'vue2-teleport' // TODO: replace with native Vue Teleport when we switch to Vue 3
import NcActionButton from '@nextcloud/vue/components/NcActionButton'
import NcActions from '@nextcloud/vue/components/NcActions'
@ -270,6 +270,14 @@ export default defineComponent({
currentView,
)
// wait until the current folder is set up to notifiy the list is initialized
const stopWatching = watch(currentFolder, () => {
if (currentFolder.value.fileid !== undefined && currentFolder.value.fileid! > 0) {
nextTick(async () => emit('files:list:initialized'))
stopWatching()
}
}, { immediate: true })
return {
currentFolder,
currentView,
@ -299,6 +307,8 @@ export default defineComponent({
data() {
return {
initialized: false,
loading: true,
loadingAction: null as string | null,
error: null as string | null,
@ -591,6 +601,8 @@ export default defineComponent({
folders.forEach((node) => {
this.pathsStore.addPath({ service: currentView.id, source: node.source, path: join(dir, node.basename) })
})
this.activeStore.activeFolder = folder
} catch (error) {
logger.error('Error while fetching content', { error })
this.error = humanizeWebDAVError(error)