diff options
author | Ferdinand Thiessen <opensource@fthiessen.de> | 2024-08-01 21:20:07 +0200 |
---|---|---|
committer | skjnldsv <skjnldsv@protonmail.com> | 2024-08-14 09:47:56 +0200 |
commit | ee4fb148b3430d64b9d7fb514ef6ea1466c006f9 (patch) | |
tree | 22027821ce82f92d25089ffd284950533c3c3135 | |
parent | 4920f9049503cc71b3d202786bb0582e75746d60 (diff) | |
download | nextcloud-server-ee4fb148b3430d64b9d7fb514ef6ea1466c006f9.tar.gz nextcloud-server-ee4fb148b3430d64b9d7fb514ef6ea1466c006f9.zip |
perf(files): Cache `getContents` function used for uploader
Instead of trigger a PROPFIND for every new-menu entry clicks,
or conflict handling of uploads, we can just use the cached content from the file store.
If we do not have any cache entry we fetch new, but otherwise this is not needed.
Signed-off-by: Ferdinand Thiessen <opensource@fthiessen.de>
-rw-r--r-- | apps/files/src/components/NewNodeDialog.vue | 2 | ||||
-rw-r--r-- | apps/files/src/store/files.ts | 28 | ||||
-rw-r--r-- | apps/files/src/views/FilesList.vue | 18 |
3 files changed, 36 insertions, 12 deletions
diff --git a/apps/files/src/components/NewNodeDialog.vue b/apps/files/src/components/NewNodeDialog.vue index 2b662d96b10..b766b230022 100644 --- a/apps/files/src/components/NewNodeDialog.vue +++ b/apps/files/src/components/NewNodeDialog.vue @@ -117,7 +117,7 @@ function submit() { } // Reset local name on props change -watch(() => props.defaultName, () => { +watch(() => [props.defaultName, props.otherNames], () => { localDefaultName.value = getUniqueName(props.defaultName, props.otherNames).trim() }) diff --git a/apps/files/src/store/files.ts b/apps/files/src/store/files.ts index f9024b0a6bd..1af675e67ce 100644 --- a/apps/files/src/store/files.ts +++ b/apps/files/src/store/files.ts @@ -14,6 +14,7 @@ import logger from '../logger' import Vue from 'vue' import { client } from '../services/WebdavClient.ts' +import { usePathsStore } from './paths.ts' const fetchNode = async (node: Node): Promise<Node> => { const propfindPayload = davGetDefaultPropfind() @@ -63,6 +64,33 @@ export const useFilesStore = function(...args) { }, actions: { + /** + * Get cached nodes within a given path + * + * @param service The service (files view) + * @param path The path relative within the service + * @returns Array of cached nodes within the path + */ + getNodesByPath(service: string, path?: string): Node[] { + const pathsStore = usePathsStore() + let folder: Folder | undefined + + // Get the containing folder from path store + if (!path || path === '/') { + folder = this.getRoot(service) + } else { + const source = pathsStore.getPath(service, path) + if (source) { + folder = this.getNode(source) as Folder | undefined + } + } + + // If we found a cache entry and the cache entry was already loaded (has children) then use it + return (folder?._children ?? []) + .map((source: string) => this.getNode(source)) + .filter(Boolean) + }, + updateNodes(nodes: Node[]) { // Update the store all at once const files = nodes.reduce((acc, node) => { diff --git a/apps/files/src/views/FilesList.vue b/apps/files/src/views/FilesList.vue index a127fd4c35c..e4c42a00038 100644 --- a/apps/files/src/views/FilesList.vue +++ b/apps/files/src/views/FilesList.vue @@ -242,6 +242,12 @@ export default defineComponent({ return async (path?: string) => { // as the path is allowed to be undefined we need to normalize the path ('//' to '/') const normalizedPath = normalize(`${this.currentFolder?.path ?? ''}/${path ?? ''}`) + // Try cache first + const nodes = this.filesStore.getNodesByPath(view.id, path) + if (nodes.length > 0) { + return nodes + } + // If not found in the files store (cache) // use the current view to fetch the content for the requested path return (await view.getContents(normalizedPath)).contents } @@ -277,7 +283,7 @@ export default defineComponent({ dirContents(): Node[] { return (this.currentFolder?._children || []) - .map(this.getNode) + .map(this.filesStore.getNode) .filter((node: Node) => !!node) }, @@ -531,16 +537,6 @@ export default defineComponent({ }, /** - * Get a cached note from the store - * - * @param {number} fileId the file id to get - * @return {Folder|File} - */ - getNode(fileId) { - return this.filesStore.getNode(fileId) - }, - - /** * Handle the node deleted event to reset open file * @param node The deleted node */ |