TagSpaces is an offline, open source, document manager with tagging support
Tsn882 performance problem in grid/list perspectives (#1669)
Stanimirf74c88931339
diff --git a/app/perspectives/grid-perspective/components/GridPagination.tsx b/app/perspectives/grid-perspective/components/GridPagination.tsxindex 100ba7be4..faf390058 100644--- a/app/perspectives/grid-perspective/components/GridPagination.tsx+++ b/app/perspectives/grid-perspective/components/GridPagination.tsx@@ -16,7 +16,7 @@**/-import React, { useEffect, useRef, useReducer } from 'react';+import React, { useEffect, useRef } from 'react';import { connect } from 'react-redux';import Typography from '@material-ui/core/Typography';import Tooltip from '@material-ui/core/Tooltip';@@ -26,6 +26,7 @@ import i18n from '-/services/i18n';import {actions as AppActions,getCurrentDirectoryColor,+ getIsMetaLoaded,getPageEntries,getSearchResultCount,isLoading@@ -42,6 +43,8 @@ import {import PlatformIO from '-/services/platform-facade';interface Props {+ isMetaLoaded: boolean;+ setIsMetaLoaded: (isLoaded: boolean) => void;className: string;style;theme: any;@@ -103,25 +106,26 @@ function GridPagination(props: Props) {} else {pageFiles = files;}- const [, forceUpdate] = useReducer(x => x + 1, 0);+ // const [, forceUpdate] = useReducer(x => x + 1, 0);useEffect(() => {- // if (PlatformIO.haveObjectStoreSupport()) {- PlatformIO.listMetaDirectoryPromise(props.currentDirectoryPath)- .then(meta => {- const dirEntriesPromises = getDirEntriesPromises();- const fileEntriesPromises = getFileEntriesPromises(meta);- const thumbs = getThumbs(meta);- updateEntries([- ...dirEntriesPromises,- ...fileEntriesPromises,- ...thumbs- ]);- return true;- })- .catch(ex => console.error(ex));- // }- }, [page.current, files]);+ if (!props.isMetaLoaded) {+ PlatformIO.listMetaDirectoryPromise(props.currentDirectoryPath)+ .then(meta => {+ props.setIsMetaLoaded(true);+ const dirEntriesPromises = getDirEntriesPromises();+ const fileEntriesPromises = getFileEntriesPromises(meta);+ const thumbs = getThumbs(meta);+ updateEntries([+ ...dirEntriesPromises,+ ...fileEntriesPromises,+ ...thumbs+ ]);+ return true;+ })+ .catch(ex => console.error(ex));+ }+ }, [page.current, files, props.isMetaLoaded]);useEffect(() => {page.current = currentPage;@@ -239,7 +243,8 @@ function GridPagination(props: Props) {const handleChange = (event, value) => {// setPage(value);page.current = value;- forceUpdate();+ props.setIsMetaLoaded(false);+ // forceUpdate();if (containerEl && containerEl.current) {containerEl.current.scrollTop = 0;}@@ -352,20 +357,23 @@ function mapStateToProps(state) {isAppLoading: isLoading(state),currentDirectoryColor: getCurrentDirectoryColor(state),searchResultCount: getSearchResultCount(state),- pageEntries: getPageEntries(state)+ pageEntries: getPageEntries(state),+ isMetaLoaded: getIsMetaLoaded(state)};}function mapActionCreatorsToProps(dispatch) {return bindActionCreators({- updateCurrentDirEntries: AppActions.updateCurrentDirEntries+ updateCurrentDirEntries: AppActions.updateCurrentDirEntries,+ setIsMetaLoaded: AppActions.setIsMetaLoaded},dispatch);}const areEqual = (prevProp: Props, nextProp: Props) =>+ nextProp.isMetaLoaded === prevProp.isMetaLoaded &&JSON.stringify(nextProp.files) === JSON.stringify(prevProp.files) &&JSON.stringify(nextProp.directories) ===JSON.stringify(prevProp.directories) &&diff --git a/app/reducers/app.ts b/app/reducers/app.tsindex daf2bff82..9aabf9970 100644--- a/app/reducers/app.ts+++ b/app/reducers/app.ts@@ -88,6 +88,7 @@ export const types = {SET_CURRENLOCATIONID: 'APP/SET_CURRENLOCATIONID',SET_CURRENDIRECTORYCOLOR: 'APP/SET_CURRENDIRECTORYCOLOR',SET_CURRENDIRECTORYPERSPECTIVE: 'APP/SET_CURRENDIRECTORYPERSPECTIVE',+ SET_IS_META_LOADED: 'APP/SET_IS_META_LOADED',SET_LAST_SELECTED_ENTRY: 'APP/SET_LAST_SELECTED_ENTRY',SET_SELECTED_ENTRIES: 'APP/SET_SELECTED_ENTRIES',SET_FILEDRAGGED: 'APP/SET_FILEDRAGGED',@@ -348,6 +349,12 @@ export default (state: any = initialState, action: any) => {}return state;}+ case types.SET_IS_META_LOADED: {+ if (state.isMetaLoaded !== action.isMetaLoaded) {+ return { ...state, isMetaLoaded: action.isMetaLoaded };+ }+ return state;+ }case types.TOGGLE_EDIT_TAG_DIALOG: {return {...state,@@ -1027,6 +1034,7 @@ export const actions = {dispatch(actions.setCurrentDirectoryPerspective(PerspectiveIDs.UNSPECIFIED));+ dispatch(actions.setIsMetaLoaded(false));prepareDirectoryContent(results,directoryPath,@@ -1202,6 +1210,10 @@ export const actions = {type: types.SET_CURRENDIRECTORYPERSPECTIVE,perspective}),+ setIsMetaLoaded: (isMetaLoaded: boolean) => ({+ type: types.SET_IS_META_LOADED,+ isMetaLoaded+ }),setSelectedEntries: (selectedEntries: Array<TS.FileSystemEntry>) => (dispatch: (action) => void) => {@@ -2249,6 +2261,7 @@ export const actions = {// Selectorsexport const currentUser = (state: any) => state.app.user;+export const getIsMetaLoaded = (state: any) => state.app.isMetaLoaded;export const getDirectoryContent = (state: any) =>state.app.currentDirectoryEntries;export const getPageEntries = (state: any) => state.app.pageEntries;