@@ -17,7 +17,6 @@ import { TableLogsService } from '../../table-logs/table-logs.service.js';
1717import { DeleteRowsFromTableDs } from '../application/data-structures/delete-row-from-table.ds.js' ;
1818import { buildCommonTableSettingsInput } from '../utils/build-common-table-settings-input.util.js' ;
1919import { convertHexDataInPrimaryKeyUtil } from '../utils/convert-hex-data-in-primary-key.util.js' ;
20- import { findObjectsWithProperties } from '../utils/find-objects-with-properties.js' ;
2120import { getUserEmailForAgent , validateConnection } from '../utils/validate-connection.util.js' ;
2221import { IDeleteRowsFromTable } from './table-use-cases.interface.js' ;
2322
@@ -87,7 +86,7 @@ export class DeleteRowsFromTableUseCase
8786 primaryKeys . forEach ( ( primaryKey ) => {
8887 Object . keys ( primaryKey ) . forEach ( ( key ) => {
8988 // eslint-disable-next-line security/detect-object-injection
90- if ( ! primaryKey [ key ] && primaryKey [ key ] !== '' ) {
89+ if ( primaryKey [ key ] === undefined ) {
9190 // eslint-disable-next-line security/detect-object-injection
9291 delete primaryKey [ key ] ;
9392 }
@@ -124,6 +123,7 @@ export class DeleteRowsFromTableUseCase
124123 ) ;
125124 }
126125
126+ const oldRowsByPrimaryKey = indexRowsByPrimaryKey ( oldRowsData , availablePrimaryColumns ) ;
127127 const deleteOperationsResults : Array < DeleteRowsFromTableResult > = [ ] ;
128128
129129 try {
@@ -132,7 +132,7 @@ export class DeleteRowsFromTableUseCase
132132 deleteOperationsResults . push ( {
133133 operationStatusResult : OperationResultStatusEnum . successfully ,
134134 row : primaryKey ,
135- old_data : findObjectsWithProperties ( oldRowsData , primaryKey ) . at ( 0 ) ?? { } ,
135+ old_data : oldRowsByPrimaryKey . get ( primaryKeyIndexKey ( primaryKey , availablePrimaryColumns ) ) ?? { } ,
136136 error : null ,
137137 affected_primary_key : primaryKey as unknown as string ,
138138 } ) ;
@@ -143,7 +143,7 @@ export class DeleteRowsFromTableUseCase
143143 deleteOperationsResults . push ( {
144144 operationStatusResult : OperationResultStatusEnum . unsuccessfully ,
145145 row : primaryKey ,
146- old_data : findObjectsWithProperties ( oldRowsData , primaryKey ) . at ( 0 ) ?? { } ,
146+ old_data : oldRowsByPrimaryKey . get ( primaryKeyIndexKey ( primaryKey , availablePrimaryColumns ) ) ?? { } ,
147147 error : getErrorMessage ( error ) ,
148148 affected_primary_key : primaryKey as unknown as string ,
149149 } ) ;
@@ -166,3 +166,19 @@ export class DeleteRowsFromTableUseCase
166166 }
167167 }
168168}
169+
170+ function primaryKeyIndexKey ( row : Record < string , unknown > , primaryColumns : Array < string > ) : string {
171+ // eslint-disable-next-line security/detect-object-injection
172+ return primaryColumns . map ( ( column ) => String ( row [ column ] ) ) . join ( '\u0000' ) ;
173+ }
174+
175+ function indexRowsByPrimaryKey (
176+ rows : Array < Record < string , unknown > > ,
177+ primaryColumns : Array < string > ,
178+ ) : Map < string , Record < string , unknown > > {
179+ const index = new Map < string , Record < string , unknown > > ( ) ;
180+ for ( const row of rows ) {
181+ index . set ( primaryKeyIndexKey ( row , primaryColumns ) , row ) ;
182+ }
183+ return index ;
184+ }
0 commit comments