From ea0af4fd05acac2ffea5e290a22b036c22b98689 Mon Sep 17 00:00:00 2001 From: Joshua Barbosa <44610149+tongsonbarbs@users.noreply.github.com> Date: Thu, 21 Nov 2024 14:16:48 +0800 Subject: [PATCH] DataGrid - Performance drops on adding a large number of rows via editing.changes (T1251098) (#28391) --- .../grids/grid_core/editing/m_editing.ts | 22 +++++++------------ 1 file changed, 8 insertions(+), 14 deletions(-) diff --git a/packages/devextreme/js/__internal/grids/grid_core/editing/m_editing.ts b/packages/devextreme/js/__internal/grids/grid_core/editing/m_editing.ts index 1a165bbbea00..4d0502106ed0 100644 --- a/packages/devextreme/js/__internal/grids/grid_core/editing/m_editing.ts +++ b/packages/devextreme/js/__internal/grids/grid_core/editing/m_editing.ts @@ -5,7 +5,8 @@ import domAdapter from '@js/core/dom_adapter'; import Guid from '@js/core/guid'; import type { dxElementWrapper } from '@js/core/renderer'; import $ from '@js/core/renderer'; -import { equalByValue } from '@js/core/utils/common'; +// @ts-expect-error +import { equalByValue, getKeyHash } from '@js/core/utils/common'; import type { DeferredObj } from '@js/core/utils/deferred'; // @ts-expect-error import { Deferred, fromPromise, when } from '@js/core/utils/deferred'; @@ -131,7 +132,7 @@ class EditingControllerImpl extends modules.ViewController { protected _saveEditorHandler: any; - private _internalState: any; + private _internalState!: Map; protected _refocusEditCell: any; @@ -193,7 +194,7 @@ class EditingControllerImpl extends modules.ViewController { this._updateEditButtons(); if (!this._internalState) { - this._internalState = []; + this._internalState = new Map(); } this.component._optionsByReference[EDITING_EDITROWKEY_OPTION_NAME] = true; @@ -272,7 +273,7 @@ class EditingControllerImpl extends modules.ViewController { } private _getInternalData(key) { - return this._internalState.filter((item) => equalByValue(item.key, key))[0]; + return this._internalState.get(getKeyHash(key)); } public _addInternalData(params) { @@ -282,7 +283,7 @@ class EditingControllerImpl extends modules.ViewController { return extend(internalData, params); } - this._internalState.push(params); + this._internalState.set(getKeyHash(params.key), params); return params; } @@ -1329,12 +1330,7 @@ class EditingControllerImpl extends modules.ViewController { } private _removeInternalData(key) { - const internalData = this._getInternalData(key); - const index = this._internalState.indexOf(internalData); - - if (index > -1) { - this._internalState.splice(index, 1); - } + this._internalState.delete(getKeyHash(key)); } private _updateInsertAfterOrBeforeKeys(changes, index) { @@ -1770,8 +1766,7 @@ class EditingControllerImpl extends modules.ViewController { return deferred.promise(); } - // @ts-expect-error - private _resolveAfterSave(deferred, { cancel, error } = {}) { + private _resolveAfterSave(deferred, { cancel = undefined, error = undefined } = {}) { // @ts-expect-error when(this._afterSaveEditData(cancel)).done(() => { deferred.resolve(error); @@ -1860,7 +1855,6 @@ class EditingControllerImpl extends modules.ViewController { }).done(() => { this._resolveAfterSave(deferred); }).fail((error) => { - // @ts-expect-error this._resolveAfterSave(deferred, { error }); }); }