From 52df4297b2e6eb526679dfbc539677005dfae764 Mon Sep 17 00:00:00 2001 From: Ferdinand Thiessen Date: Wed, 11 Feb 2026 23:29:14 +0100 Subject: [PATCH] perf(files): only emit initialization once Signed-off-by: Ferdinand Thiessen --- apps/files/src/eventbus.d.ts | 2 ++ apps/files/src/store/active.ts | 15 ++------------- apps/files/src/views/FilesList.vue | 14 +++++++++++++- 3 files changed, 17 insertions(+), 14 deletions(-) diff --git a/apps/files/src/eventbus.d.ts b/apps/files/src/eventbus.d.ts index c025564d227..e30ea3ffc28 100644 --- a/apps/files/src/eventbus.d.ts +++ b/apps/files/src/eventbus.d.ts @@ -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 diff --git a/apps/files/src/store/active.ts b/apps/files/src/store/active.ts index df8f43fd93b..1b2b48b90c7 100644 --- a/apps/files/src/store/active.ts +++ b/apps/files/src/store/active.ts @@ -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() - const filesStore = useFilesStore() - const { directory } = useRouteParameters() /** * The currently active folder */ - const activeFolder = computed(() => { - if (!activeView.value?.id) { - return dummyFolder - } - - return filesStore.getDirectoryByPath(activeView.value.id, directory.value) - ?? dummyFolder - }) + const activeFolder = ref(dummyFolder) // Set the active node on the router params watch(activeNode, () => { diff --git a/apps/files/src/views/FilesList.vue b/apps/files/src/views/FilesList.vue index f8afea583b8..61bda28894f 100644 --- a/apps/files/src/views/FilesList.vue +++ b/apps/files/src/views/FilesList.vue @@ -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)