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

Improve performance of share indicators #7188

Merged
merged 1 commit into from
Jun 30, 2022
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
6 changes: 6 additions & 0 deletions changelog/unreleased/enhancement-share-indicators-performance
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
Enhancement: Improve performance of share indicators

We've improved the performance of share indicators when loading resource tables as well as when adding or removing shares.

https://github.com/owncloud/web/issues/7038
https://github.com/owncloud/web/pull/7188
Original file line number Diff line number Diff line change
Expand Up @@ -39,20 +39,17 @@ export class FolderLoaderLegacyPersonal implements FolderLoader {
resources = resources.map(buildResource)

const currentFolder = resources.shift()
yield store.dispatch('Files/loadSharesTree', {
client,
path: currentFolder.path
})

store.commit('Files/LOAD_FILES', {
currentFolder,
files: resources
files: resources,
loadIndicators: true
})

// load indicators
;(() => {
store.dispatch('Files/loadIndicators', {
client: client,
currentFolder: currentFolder.path
})
})()

// fetch user quota
;(async () => {
const user = await client.users.getUser(router.currentRoute.params.storageId)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -36,19 +36,17 @@ export class FolderLoaderSpacesPersonal implements FolderLoader {

const currentFolder = resources.shift()

yield store.dispatch('Files/loadSharesTree', {
client: clientService.owncloudSdk,
path: currentFolder.path
})

store.commit('Files/LOAD_FILES', {
currentFolder,
files: resources
files: resources,
loadIndicators: true
})

// load indicators
;(() => {
store.dispatch('Files/loadIndicators', {
client: clientService.owncloudSdk,
currentFolder: currentFolder.path
})
})()

// fetch user quota
;(async () => {
const user = await clientService.owncloudSdk.users.getUser(ref.user.id)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -65,16 +65,17 @@ export class FolderLoaderSpacesProject implements FolderLoader {
}

const currentFolder = resources.shift()
yield store.dispatch('Files/loadSharesTree', {
client: clientService.owncloudSdk,
path: currentFolder.path
})

ref.LOAD_FILES({
currentFolder,
files: resources
})
ref.loadIndicators({
client: ref.$client,
currentFolder: currentFolder?.path,
storageId: space.id
files: resources,
loadIndicators: true
})

ref.UPSERT_SPACE(space)

if (!sameRoute) {
Expand Down
2 changes: 1 addition & 1 deletion packages/web-app-files/src/store/actions.js
Original file line number Diff line number Diff line change
Expand Up @@ -730,7 +730,7 @@ export default {
// TODO: when we refactor the shares tree we want to modify shares tree nodes incrementally during adding and removing shares, not loading everything new from the backend.
commit('SHARESTREE_PRUNE_OUTSIDE_PATH', dirname(currentFolder))
await dispatch('loadSharesTree', { client, path: currentFolder, storageId })
commit('LOAD_INDICATORS')
commit('LOAD_INDICATORS', currentFolder)
},

loadAvatars({ commit, rootGetters }, { resource }) {
Expand Down
14 changes: 11 additions & 3 deletions packages/web-app-files/src/store/mutations.js
Original file line number Diff line number Diff line change
Expand Up @@ -53,8 +53,15 @@ export default {
CLEAR_SPACES(state) {
state.spaces = []
},
LOAD_FILES(state, { currentFolder, files }) {
LOAD_FILES(state, { currentFolder, files, loadIndicators = false }) {
state.currentFolder = currentFolder

if (loadIndicators) {
for (const file of files) {
file.indicators = getIndicators(file, state.sharesTree)
}
}

state.files = files
},
SET_CURRENT_FOLDER(state, currentFolder) {
Expand Down Expand Up @@ -238,8 +245,9 @@ export default {
state.versions = versions
},

LOAD_INDICATORS(state) {
for (const resource of state.files) {
LOAD_INDICATORS(state, path) {
const files = state.files.filter((f) => f.path.startsWith(path))
for (const resource of files) {
const indicators = getIndicators(resource, state.sharesTree)

if (!indicators.length && !resource.indicators.length) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -144,7 +144,7 @@ describe('Spaces project view', () => {
})
})

const wrapper = getMountedWrapper([], { id: 1 })
const wrapper = getMountedWrapper([Files['/'][0]], { id: 1 })
await wrapper.vm.loadResourcesTask.last

expect(wrapper.find(selectors.spaceImage).exists()).toBeFalsy()
Expand Down Expand Up @@ -285,7 +285,8 @@ function getMountedWrapper(spaceResources = [], spaceItem = null, imageContent =
},
actions: {
loadIndicators: jest.fn(),
loadCurrentFileOutgoingShares: jest.fn()
loadCurrentFileOutgoingShares: jest.fn(),
loadSharesTree: jest.fn()
},
getters: {
activeFiles: () => spaceResources,
Expand Down