TagSpaces is an offline, open source, document manager with tagging support
chore: performance optimizations
Ilian Sapundshiev68c2ec3f2ac9
diff --git a/app/perspectives/grid-perspective/components/CellContent.tsx b/app/perspectives/grid-perspective/components/CellContent.tsxindex 1cc786b05..a9fc75fa0 100644--- a/app/perspectives/grid-perspective/components/CellContent.tsx+++ b/app/perspectives/grid-perspective/components/CellContent.tsx@@ -16,7 +16,7 @@**/-import React from 'react';+import React, { useMemo } from 'react';import classNames from 'classnames';import Grid from '@mui/material/Grid';import Typography from '@mui/material/Typography';@@ -103,6 +103,7 @@ function CellContent(props: Props) {thumbnailMode,addTags,addTag,+ editTagForEntry,selectedEntries,isReadOnlyMode,handleTagMenu,@@ -110,10 +111,13 @@ function CellContent(props: Props) {handleGridContextMenu,handleGridCellDblClick,handleGridCellClick,+ lastThumbnailImageChange,+ showEntriesDescription,showTags,// openFsEntry,selectEntry,deselectEntry,+ reorderTags,isDesktopMode,isLast} = props;@@ -130,7 +134,7 @@ function CellContent(props: Props) {);let description;- if (props.showEntriesDescription) {+ if (showEntriesDescription) {description = fSystemEntry.description;if (description && description.length > maxDescriptionPreviewLength) {description = getDescriptionPreview(@@ -166,6 +170,23 @@ function CellContent(props: Props) {...fileNameTags.filter(tag => !sideCarTagsTitles.includes(tag.title))];+ const entrySizeFormatted =+ fSystemEntry.isFile && formatFileSize(fSystemEntry.size) + ' | ';+ const entryLMDTFormatted =+ fSystemEntry.isFile &&+ fSystemEntry.lmdt &&+ formatDateTime(fSystemEntry.lmdt, true);++ let tmbSize = 85;+ const isSmall = entrySize === 'small';+ if (isSmall) {+ tmbSize = 30;+ } else if (entrySize === 'normal') {+ tmbSize = 70;+ } else if (entrySize === 'big') {+ tmbSize = 100;+ }+let tagTitles = '';if (entryTags) {entryTags.map(tag => {@@ -203,13 +224,12 @@ function CellContent(props: Props) {className={classes.gridCellThumb}src={fSystemEntry.thumbPath +- (props.lastThumbnailImageChange &&- props.lastThumbnailImageChange.thumbPath ===- fSystemEntry.thumbPath &&+ (lastThumbnailImageChange &&+ lastThumbnailImageChange.thumbPath === fSystemEntry.thumbPath &&!PlatformIO.haveObjectStoreSupport() &&!PlatformIO.haveWebDavSupport()? urlGetDelim(fSystemEntry.thumbPath) +- props.lastThumbnailImageChange.dt+ lastThumbnailImageChange.dt: '')}// @ts-ignore@@ -250,7 +270,7 @@ function CellContent(props: Props) {>{selected ? <SelectedIcon /> : <UnSelectedIcon />}</IconButton>- {showTags && entryTags ? renderTags(entryTags) : tagPlaceholder}+ {showTags && entryTags ? renderTags : tagPlaceholder}</div>{description && (<Tooltip title={i18n.t('core:entryDescription')}>@@ -310,27 +330,11 @@ function CellContent(props: Props) {);}- function renderRowCell(selected: boolean) {- const isSmall = entrySize === 'small';- let tmbSize = 85;- if (isSmall) {- tmbSize = 30;- } else if (entrySize === 'normal') {- tmbSize = 70;- } else if (entrySize === 'big') {- tmbSize = 100;- }+ function renderRowCell() {const backgroundColor = selected? theme.palette.primary.light: fileSystemEntryBgColor;- const entrySizeFormatted =- fSystemEntry.isFile && formatFileSize(fSystemEntry.size) + ' | ';- const entryLMDTFormatted =- fSystemEntry.isFile &&- fSystemEntry.lmdt &&- formatDateTime(fSystemEntry.lmdt, true);-return (<Gridcontainer@@ -413,7 +417,7 @@ function CellContent(props: Props) {<>{entryTitle}</></Tooltip> - {showTags && entryTags ? renderTags(entryTags) : tagPlaceholder}+ {showTags && entryTags ? renderTags : tagPlaceholder}</Typography></Grid>) : (@@ -423,7 +427,7 @@ function CellContent(props: Props) {{entryTitle}</Typography></Tooltip>- {showTags && entryTags ? renderTags(entryTags) : tagPlaceholder}+ {showTags && entryTags ? renderTags : tagPlaceholder}<Typographystyle={{color: 'gray'@@ -457,13 +461,12 @@ function CellContent(props: Props) {className={classes.gridCellThumb}src={fSystemEntry.thumbPath +- (props.lastThumbnailImageChange &&- props.lastThumbnailImageChange.thumbPath ===- fSystemEntry.thumbPath &&+ (lastThumbnailImageChange &&+ lastThumbnailImageChange.thumbPath === fSystemEntry.thumbPath &&!PlatformIO.haveObjectStoreSupport() &&!PlatformIO.haveWebDavSupport()? urlGetDelim(fSystemEntry.thumbPath) +- props.lastThumbnailImageChange.dt+ lastThumbnailImageChange.dt: '')}// @ts-ignore@@ -483,14 +486,16 @@ function CellContent(props: Props) {);}- function renderTags(tags: Array<TS.Tag>) {+ const entryPath = fSystemEntry.path;++ const renderTags = useMemo(() => {let sideCarLength = 0;- return tags.map((tag: TS.Tag, index) => {+ return entryTags.map((tag: TS.Tag, index) => {const tagContainer = isReadOnlyMode ? (<TagContainertag={tag}- key={fSystemEntry.path + tag.title}- entryPath={fSystemEntry.path}+ key={entryPath + tag.title}+ entryPath={entryPath}addTags={addTags}handleTagMenu={handleTagMenu}selectedEntries={selectedEntries}@@ -499,14 +504,14 @@ function CellContent(props: Props) {<TagContainerDndtag={tag}index={tag.type === 'sidecar' ? index : index - sideCarLength}- key={fSystemEntry.path + tag.title}- entryPath={fSystemEntry.path}+ key={entryPath + tag.title}+ entryPath={entryPath}addTags={addTags}addTag={addTag}handleTagMenu={handleTagMenu}selectedEntries={selectedEntries}- editTagForEntry={props.editTagForEntry}- reorderTags={props.reorderTags}+ editTagForEntry={editTagForEntry}+ reorderTags={reorderTags}/>);@@ -515,7 +520,7 @@ function CellContent(props: Props) {}return tagContainer;});- }+ }, [entryTags, isReadOnlyMode, reorderTags, entryPath, selectedEntries]);let entryHeight = 130;if (entrySize === 'small') {@@ -526,13 +531,6 @@ function CellContent(props: Props) {entryHeight = 100;}- let gridCell: any = React.Fragment;- if (layoutType === 'grid') {- gridCell = renderGridCell();- } else if (layoutType === 'row') {- gridCell = renderRowCell(selected);- }-return (<Paperelevation={2}@@ -550,7 +548,6 @@ function CellContent(props: Props) {}}onContextMenu={event => handleGridContextMenu(event, fSystemEntry)}onDoubleClick={event => {- // props.exitSearchMode();handleGridCellDblClick(event, fSystemEntry);}}onClick={event => {@@ -560,11 +557,11 @@ function CellContent(props: Props) {: handleGridCellClick(event, fSystemEntry);}}onDrag={event => {- // event.stopPropagation();handleGridCellClick(event, fSystemEntry);}}>- {gridCell}+ {layoutType === 'grid' && renderGridCell()}+ {layoutType === 'row' && renderRowCell()}</Paper>);}