Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix(resource loading): don't load root resources twice if homeFolder is set #5893

Merged
merged 4 commits into from
Oct 13, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
Bugfix: Unnecessary redirects on personal page

Navigating to all files could lead to loading resources twice, first resources from root (/) and second the resources from the homeFolder (options.homeFolder).
We've fixed this by detecting those cases and only load resources for the homeFolder.

https://github.com/owncloud/web/pull/5893
https://github.com/owncloud/web/issues/5085
https://github.com/owncloud/web/issues/5875
67 changes: 27 additions & 40 deletions packages/web-app-files/src/views/Personal.vue
Original file line number Diff line number Diff line change
Expand Up @@ -108,22 +108,6 @@ export default {
MixinFilesListFilter
],

beforeRouteEnter(to, from, next) {
next((vm) => {
if (vm.isRedirectToHomeFolderRequired(to)) {
vm.redirectToHomeFolder(to)
}
})
},

async beforeRouteUpdate(to, from, next) {
if (this.isRedirectToHomeFolderRequired(to)) {
await this.redirectToHomeFolder(to)
return
}
next()
},

data: () => ({
loading: true
}),
Expand Down Expand Up @@ -177,10 +161,35 @@ export default {
watch: {
$route: {
handler: function (to, from) {
this.$_filesListPagination_updateCurrentPage()

const sameRoute = to.name === from?.name
const sameItem = to.params?.item === from?.params?.item

const needsRedirectToHome =
this.homeFolder !== '/' &&
isNil(to.params.item) &&
!to.path.endsWith('/') &&
(!sameRoute || !sameItem)
if (needsRedirectToHome) {
this.$router.replace(
{
name: to.name,
params: {
...to.params,
item: this.homeFolder
},
query: to.query
},
() => {},
(e) => {
console.error(e)
}
)

return
}

this.$_filesListPagination_updateCurrentPage()

if (!sameRoute || !sameItem) {
this.loadResources(sameRoute)
}
Expand Down Expand Up @@ -223,28 +232,6 @@ export default {
]),
...mapMutations(['SET_QUOTA']),

isRedirectToHomeFolderRequired(to) {
return isNil(to.params.item)
},

async redirectToHomeFolder(to) {
const route = {
name: to.name,
params: {
...to.params,
item: to.path.endsWith('/') ? '/' : this.homeFolder
},
query: to.query
}
await this.$router.replace(
route,
() => {},
(e) => {
console.error(e)
}
)
},

async fileDropped(fileIdTarget) {
const selected = [...this.selectedFiles]
const targetInfo = this.activeFilesCurrentPage.find((e) => e.id === fileIdTarget)
Expand Down