Merge pull request #46966 from nextcloud/fix/cache-uploader-get-content-function

This commit is contained in:
John Molakvoæ 2024-08-14 10:18:38 +02:00 committed by GitHub
commit dbc2e9cdba
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
7 changed files with 42 additions and 18 deletions

View file

@ -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()
})

View file

@ -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) => {

View file

@ -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)
},
@ -530,16 +536,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

4
dist/files-init.js vendored

File diff suppressed because one or more lines are too long

File diff suppressed because one or more lines are too long

4
dist/files-main.js vendored

File diff suppressed because one or more lines are too long

File diff suppressed because one or more lines are too long