From b626c92353bec036ce14a8b9fe887617de9f1322 Mon Sep 17 00:00:00 2001 From: Aleksei Potsetsuev Date: Sun, 21 Jan 2024 21:17:38 +0800 Subject: [PATCH] chore: performance improvements --- .../src/Tree/TreeNode/TreeNodeIcon.m.css | 1 + .../src/Tree/TreeNode/TreeNodeNested.tsx | 1 - .../core-ui/src/DragAndDrop/useDNDData.ts | 2 +- webapp/packages/core-utils/src/TempMap.ts | 19 ++++++++----------- .../NavigationTreeNode/useNavigationNode.ts | 4 +--- 5 files changed, 11 insertions(+), 16 deletions(-) diff --git a/webapp/packages/core-blocks/src/Tree/TreeNode/TreeNodeIcon.m.css b/webapp/packages/core-blocks/src/Tree/TreeNode/TreeNodeIcon.m.css index 20eb274d11..8dd258248a 100644 --- a/webapp/packages/core-blocks/src/Tree/TreeNode/TreeNodeIcon.m.css +++ b/webapp/packages/core-blocks/src/Tree/TreeNode/TreeNodeIcon.m.css @@ -1,6 +1,7 @@ .treeNodeIcon { position: relative; box-sizing: border-box; + pointer-events: none; flex-shrink: 0; width: 16px; height: 16px; diff --git a/webapp/packages/core-blocks/src/Tree/TreeNode/TreeNodeNested.tsx b/webapp/packages/core-blocks/src/Tree/TreeNode/TreeNodeNested.tsx index b379a6922a..1abdf77717 100644 --- a/webapp/packages/core-blocks/src/Tree/TreeNode/TreeNodeNested.tsx +++ b/webapp/packages/core-blocks/src/Tree/TreeNode/TreeNodeNested.tsx @@ -13,7 +13,6 @@ import { useS } from '../../useS'; import style from './TreeNodeNested.m.css'; interface Props extends React.PropsWithChildren { - expanded?: boolean; root?: boolean; className?: string; } diff --git a/webapp/packages/core-ui/src/DragAndDrop/useDNDData.ts b/webapp/packages/core-ui/src/DragAndDrop/useDNDData.ts index ab46528e1c..7c3cfe6ec1 100644 --- a/webapp/packages/core-ui/src/DragAndDrop/useDNDData.ts +++ b/webapp/packages/core-ui/src/DragAndDrop/useDNDData.ts @@ -68,7 +68,7 @@ export function useDNDData(context: IDataContextProvider, options: IOptions = {} } } - state.isDragging = monitor.isDragging(); + state.isDragging = dragging; }, })); diff --git a/webapp/packages/core-utils/src/TempMap.ts b/webapp/packages/core-utils/src/TempMap.ts index cf63ec3d77..144d3c29ff 100644 --- a/webapp/packages/core-utils/src/TempMap.ts +++ b/webapp/packages/core-utils/src/TempMap.ts @@ -23,7 +23,7 @@ export class TempMap implements Map { return 'TempMap'; } - private readonly deleted: TKey[]; + private readonly deleted: Map; private readonly temp: Map; private flushTask: NodeJS.Timeout | null; private readonly keysTemp: ICachedValueObject; @@ -33,7 +33,7 @@ export class TempMap implements Map { constructor(private readonly target: Map, private readonly onSync?: () => void) { this.temp = new Map(); this.flushTask = null; - this.deleted = []; + this.deleted = new Map(); this.keysTemp = cacheValue(); this.entriesTemp = cacheValue(); this.valuesTemp = cacheValue(); @@ -45,7 +45,7 @@ export class TempMap implements Map { } isDeleted(key: TKey): boolean { - return this.deleted.includes(key); + return this.deleted.get(key) || false; } /** @@ -56,7 +56,7 @@ export class TempMap implements Map { clearTimeout(this.flushTask); this.flushTask = null; } - this.deleted.splice(0, this.deleted.length); + this.deleted.clear(); this.temp.clear(); this.keysTemp.invalidate(); this.valuesTemp.invalidate(); @@ -65,7 +65,7 @@ export class TempMap implements Map { delete(key: TKey): boolean { this.temp.delete(key); - this.deleted.push(key); + this.deleted.set(key, true); this.scheduleFlush(); return this.has(key); } @@ -105,10 +105,7 @@ export class TempMap implements Map { set(key: TKey, value: TValue): this { this.temp.set(key, value); - const indexOfDeleted = this.deleted.indexOf(key); - if (indexOfDeleted !== -1) { - this.deleted.splice(indexOfDeleted, 1); - } + this.deleted.delete(key); this.scheduleFlush(); return this; @@ -139,10 +136,10 @@ export class TempMap implements Map { this.flushTask = setTimeout( action(() => { - for (const deleted of this.deleted) { + for (const [deleted] of this.deleted) { this.target.delete(deleted); } - this.deleted.splice(0, this.deleted.length); + this.deleted.clear(); for (const [key, value] of this.temp) { this.target.set(key, value); diff --git a/webapp/packages/plugin-navigation-tree/src/NavigationTree/ElementsTree/NavigationTreeNode/useNavigationNode.ts b/webapp/packages/plugin-navigation-tree/src/NavigationTree/ElementsTree/NavigationTreeNode/useNavigationNode.ts index 7f296afb28..d1d72f5ad3 100644 --- a/webapp/packages/plugin-navigation-tree/src/NavigationTree/ElementsTree/NavigationTreeNode/useNavigationNode.ts +++ b/webapp/packages/plugin-navigation-tree/src/NavigationTree/ElementsTree/NavigationTreeNode/useNavigationNode.ts @@ -9,7 +9,6 @@ import React, { useContext, useEffect, useRef } from 'react'; import { getComputed, useExecutor, useObjectRef } from '@cloudbeaver/core-blocks'; import { useService } from '@cloudbeaver/core-di'; -import { SyncExecutor } from '@cloudbeaver/core-executor'; import { EObjectFeature, type NavNode, NavNodeInfoResource } from '@cloudbeaver/core-navigation-tree'; import { resourceKeyList } from '@cloudbeaver/core-resource'; import type { IDNDData } from '@cloudbeaver/core-ui'; @@ -17,7 +16,6 @@ import type { IDNDData } from '@cloudbeaver/core-ui'; import { useChildren } from '../../../NodesManager/useChildren'; import { useNode } from '../../../NodesManager/useNode'; import { ElementsTreeContext } from '../ElementsTreeContext'; -import type { IElementsTreeAction } from '../IElementsTreeAction'; import type { NavTreeControlComponent } from '../NavigationNodeComponent'; import type { IElementsTree } from '../useElementsTree'; @@ -94,7 +92,7 @@ export function useNavigationNode(node: NavNode, path: string[]): INavigationNod }, []); useExecutor({ - executor: contextRef.context?.tree.actions || new SyncExecutor(), + executor: contextRef.context?.tree.actions, handlers: [ function refreshRoot({ type, nodeId }) { if (type === 'show' && nodeId === node.id) {