aboutsummaryrefslogtreecommitdiffstats
path: root/apps/files/src/store/files.ts
diff options
context:
space:
mode:
authorFerdinand Thiessen <opensource@fthiessen.de>2024-08-01 21:20:07 +0200
committerskjnldsv <skjnldsv@protonmail.com>2024-08-14 09:47:56 +0200
commitee4fb148b3430d64b9d7fb514ef6ea1466c006f9 (patch)
tree22027821ce82f92d25089ffd284950533c3c3135 /apps/files/src/store/files.ts
parent4920f9049503cc71b3d202786bb0582e75746d60 (diff)
downloadnextcloud-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>
Diffstat (limited to 'apps/files/src/store/files.ts')
-rw-r--r--apps/files/src/store/files.ts28
1 files changed, 28 insertions, 0 deletions
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) => {