From ee4fb148b3430d64b9d7fb514ef6ea1466c006f9 Mon Sep 17 00:00:00 2001 From: Ferdinand Thiessen Date: Thu, 1 Aug 2024 21:20:07 +0200 Subject: 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 --- apps/files/src/store/files.ts | 28 ++++++++++++++++++++++++++++ 1 file changed, 28 insertions(+) (limited to 'apps/files/src/store/files.ts') 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 => { 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) => { -- cgit v1.2.3