Skip to content

Commit

Permalink
perf(files): performance optimizations
Browse files Browse the repository at this point in the history
Signed-off-by: Varun Patil <varunpatil@ucla.edu>
  • Loading branch information
pulsejet authored and skjnldsv committed Oct 19, 2023
1 parent 1c014f8 commit 4876eac
Show file tree
Hide file tree
Showing 4 changed files with 25 additions and 15 deletions.
11 changes: 7 additions & 4 deletions apps/files/src/components/FileEntry/FileEntryActions.vue
Original file line number Diff line number Diff line change
Expand Up @@ -35,8 +35,8 @@
<!-- Menu actions -->
<NcActions v-if="visible"
ref="actionsMenu"
:boundaries-element="getBoundariesElement()"
:container="getBoundariesElement()"
:boundaries-element="getBoundariesElement"
:container="getBoundariesElement"
:disabled="isLoading || loading !== ''"
:force-name="true"
:force-menu="enabledInlineActions.length === 0 /* forceMenu only if no inline actions */"
Expand Down Expand Up @@ -70,6 +70,8 @@ import NcActions from '@nextcloud/vue/dist/Components/NcActions.js'
import NcIconSvgWrapper from '@nextcloud/vue/dist/Components/NcIconSvgWrapper.js'
import NcLoadingIcon from '@nextcloud/vue/dist/Components/NcLoadingIcon.js'
import CustomElementRender from '../CustomElementRender.vue'
import logger from '../../logger.js'
// The registered actions list
Expand All @@ -83,6 +85,7 @@ export default Vue.extend({
NcActions,
NcIconSvgWrapper,
NcLoadingIcon,
CustomElementRender,
},
props: {
Expand Down Expand Up @@ -182,9 +185,7 @@ export default Vue.extend({
this.$emit('update:opened', value)
},
},
},
methods: {
/**
* Making this a function in case the files-list
* reference changes in the future. That way we're
Expand All @@ -193,7 +194,9 @@ export default Vue.extend({
getBoundariesElement() {
return document.querySelector('.app-content > table.files-list')
},
},
methods: {
actionDisplayName(action: FileAction) {
if (this.filesListWidth < 768 && action.inline && typeof action.title === 'function') {
// if an inline action is rendered in the menu for
Expand Down
8 changes: 4 additions & 4 deletions apps/files/src/components/FileEntry/FileEntryPreview.vue
Original file line number Diff line number Diff line change
Expand Up @@ -22,9 +22,9 @@
<template>
<span class="files-list__row-icon">
<template v-if="source.type === 'folder'">
<FolderOpenIcon v-if="dragover" />
<FolderOpenIcon v-once v-if="dragover" />
<template v-else>
<FolderIcon />
<FolderIcon v-once />
<OverlayIcon :is="folderOverlay"
v-if="folderOverlay"
class="files-list__row-icon-overlay" />
Expand All @@ -41,13 +41,13 @@
@error="backgroundFailed = true"
@load="backgroundFailed = false">

<FileIcon v-else />
<FileIcon v-once v-else />

<!-- Favorite icon -->
<span v-if="isFavorite"
class="files-list__row-icon-favorite"
:aria-label="t('files', 'Favorite')">
<FavoriteIcon />
<FavoriteIcon v-once />
</span>
</span>
</template>
Expand Down
4 changes: 4 additions & 0 deletions apps/files/src/components/FilesListVirtual.vue
Original file line number Diff line number Diff line change
Expand Up @@ -312,6 +312,8 @@ export default Vue.extend({
&::v-deep {
// Table head, body and footer
tbody {
will-change: scroll-position, padding;
contain: layout paint style;
display: flex;
flex-direction: column;
width: 100%;
Expand All @@ -320,6 +322,7 @@ export default Vue.extend({
/* Hover effect on tbody lines only */
tr {
contain: strict;
&:hover,
&:focus {
background-color: var(--color-background-dark);
Expand All @@ -329,6 +332,7 @@ export default Vue.extend({
// Before table and thead
.files-list__before {
contain: strict;
display: flex;
flex-direction: column;
}
Expand Down
17 changes: 10 additions & 7 deletions apps/files/src/components/VirtualList.vue
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@
<component :is="dataComponent"
v-for="({key, item}, i) in renderedItems"
:key="key"
:visible="(i >= bufferItems - 1 || index <= bufferItems) && (i <= shownItems - bufferItems)"
:visible="true"
:source="item"
:index="i"
v-bind="extraProps" />
Expand Down Expand Up @@ -211,7 +211,7 @@ export default Vue.extend({
}
// Adding scroll listener AFTER the initial scroll to index
this.$el.addEventListener('scroll', this.onScroll)
this.$el.addEventListener('scroll', this.onScroll, { passive: true })
this.$_recycledPool = {} as Record<string, any>
},
Expand All @@ -232,11 +232,14 @@ export default Vue.extend({
},
onScroll() {
const topScroll = this.$el.scrollTop - this.beforeHeight
const index = Math.floor(topScroll / this.itemHeight) * this.columnCount
// Max 0 to prevent negative index
this.index = Math.max(0, index)
this.$emit('scroll')
this._onScrollHandle ??= requestAnimationFrame(() => {
this._onScrollHandle = null;
const topScroll = this.$el.scrollTop - this.beforeHeight
const index = Math.floor(topScroll / this.itemHeight) * this.columnCount
// Max 0 to prevent negative index
this.index = Math.max(0, index)
this.$emit('scroll')
});
},
},
})
Expand Down

0 comments on commit 4876eac

Please sign in to comment.