Skip to content

Commit

Permalink
chore: performance improvements (#2319)
Browse files Browse the repository at this point in the history
  • Loading branch information
Wroud authored Jan 21, 2024
1 parent a230dac commit 6b12407
Show file tree
Hide file tree
Showing 5 changed files with 11 additions and 16 deletions.
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
.treeNodeIcon {
position: relative;
box-sizing: border-box;
pointer-events: none;
flex-shrink: 0;
width: 16px;
height: 16px;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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;
}
Expand Down
2 changes: 1 addition & 1 deletion webapp/packages/core-ui/src/DragAndDrop/useDNDData.ts
Original file line number Diff line number Diff line change
Expand Up @@ -68,7 +68,7 @@ export function useDNDData(context: IDataContextProvider, options: IOptions = {}
}
}

state.isDragging = monitor.isDragging();
state.isDragging = dragging;
},
}));

Expand Down
19 changes: 8 additions & 11 deletions webapp/packages/core-utils/src/TempMap.ts
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ export class TempMap<TKey, TValue> implements Map<TKey, TValue> {
return 'TempMap';
}

private readonly deleted: TKey[];
private readonly deleted: Map<TKey, boolean>;
private readonly temp: Map<TKey, TValue>;
private flushTask: NodeJS.Timeout | null;
private readonly keysTemp: ICachedValueObject<TKey[]>;
Expand All @@ -33,7 +33,7 @@ export class TempMap<TKey, TValue> implements Map<TKey, TValue> {
constructor(private readonly target: Map<TKey, TValue>, 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();
Expand All @@ -45,7 +45,7 @@ export class TempMap<TKey, TValue> implements Map<TKey, TValue> {
}

isDeleted(key: TKey): boolean {
return this.deleted.includes(key);
return this.deleted.get(key) || false;
}

/**
Expand All @@ -56,7 +56,7 @@ export class TempMap<TKey, TValue> implements Map<TKey, TValue> {
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();
Expand All @@ -65,7 +65,7 @@ export class TempMap<TKey, TValue> implements Map<TKey, TValue> {

delete(key: TKey): boolean {
this.temp.delete(key);
this.deleted.push(key);
this.deleted.set(key, true);
this.scheduleFlush();
return this.has(key);
}
Expand Down Expand Up @@ -105,10 +105,7 @@ export class TempMap<TKey, TValue> implements Map<TKey, TValue> {
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;
Expand Down Expand Up @@ -139,10 +136,10 @@ export class TempMap<TKey, TValue> implements Map<TKey, TValue> {

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);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,15 +9,13 @@ 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';

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';

Expand Down Expand Up @@ -94,7 +92,7 @@ export function useNavigationNode(node: NavNode, path: string[]): INavigationNod
}, []);

useExecutor({
executor: contextRef.context?.tree.actions || new SyncExecutor<IElementsTreeAction>(),
executor: contextRef.context?.tree.actions,
handlers: [
function refreshRoot({ type, nodeId }) {
if (type === 'show' && nodeId === node.id) {
Expand Down

0 comments on commit 6b12407

Please sign in to comment.