Skip to content

Commit dbc2e9c

Browse files
authored
Merge pull request #46966 from nextcloud/fix/cache-uploader-get-content-function
2 parents 1044b7f + c60e59c commit dbc2e9c

File tree

7 files changed

+42
-18
lines changed

7 files changed

+42
-18
lines changed

apps/files/src/components/NewNodeDialog.vue

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -117,7 +117,7 @@ function submit() {
117117
}
118118
119119
// Reset local name on props change
120-
watch(() => props.defaultName, () => {
120+
watch(() => [props.defaultName, props.otherNames], () => {
121121
localDefaultName.value = getUniqueName(props.defaultName, props.otherNames).trim()
122122
})
123123

apps/files/src/store/files.ts

Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,7 @@ import logger from '../logger'
1414
import Vue from 'vue'
1515

1616
import { client } from '../services/WebdavClient.ts'
17+
import { usePathsStore } from './paths.ts'
1718

1819
const fetchNode = async (node: Node): Promise<Node> => {
1920
const propfindPayload = davGetDefaultPropfind()
@@ -63,6 +64,33 @@ export const useFilesStore = function(...args) {
6364
},
6465

6566
actions: {
67+
/**
68+
* Get cached nodes within a given path
69+
*
70+
* @param service The service (files view)
71+
* @param path The path relative within the service
72+
* @returns Array of cached nodes within the path
73+
*/
74+
getNodesByPath(service: string, path?: string): Node[] {
75+
const pathsStore = usePathsStore()
76+
let folder: Folder | undefined
77+
78+
// Get the containing folder from path store
79+
if (!path || path === '/') {
80+
folder = this.getRoot(service)
81+
} else {
82+
const source = pathsStore.getPath(service, path)
83+
if (source) {
84+
folder = this.getNode(source) as Folder | undefined
85+
}
86+
}
87+
88+
// If we found a cache entry and the cache entry was already loaded (has children) then use it
89+
return (folder?._children ?? [])
90+
.map((source: string) => this.getNode(source))
91+
.filter(Boolean)
92+
},
93+
6694
updateNodes(nodes: Node[]) {
6795
// Update the store all at once
6896
const files = nodes.reduce((acc, node) => {

apps/files/src/views/FilesList.vue

Lines changed: 7 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -242,6 +242,12 @@ export default defineComponent({
242242
return async (path?: string) => {
243243
// as the path is allowed to be undefined we need to normalize the path ('//' to '/')
244244
const normalizedPath = normalize(`${this.currentFolder?.path ?? ''}/${path ?? ''}`)
245+
// Try cache first
246+
const nodes = this.filesStore.getNodesByPath(view.id, path)
247+
if (nodes.length > 0) {
248+
return nodes
249+
}
250+
// If not found in the files store (cache)
245251
// use the current view to fetch the content for the requested path
246252
return (await view.getContents(normalizedPath)).contents
247253
}
@@ -277,7 +283,7 @@ export default defineComponent({
277283
278284
dirContents(): Node[] {
279285
return (this.currentFolder?._children || [])
280-
.map(this.getNode)
286+
.map(this.filesStore.getNode)
281287
.filter((node: Node) => !!node)
282288
},
283289
@@ -530,16 +536,6 @@ export default defineComponent({
530536
531537
},
532538
533-
/**
534-
* Get a cached note from the store
535-
*
536-
* @param {number} fileId the file id to get
537-
* @return {Folder|File}
538-
*/
539-
getNode(fileId) {
540-
return this.filesStore.getNode(fileId)
541-
},
542-
543539
/**
544540
* Handle the node deleted event to reset open file
545541
* @param node The deleted node

dist/files-init.js

Lines changed: 2 additions & 2 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

dist/files-init.js.map

Lines changed: 1 addition & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

dist/files-main.js

Lines changed: 2 additions & 2 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

dist/files-main.js.map

Lines changed: 1 addition & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

0 commit comments

Comments
 (0)