CE-1955 Memoize groupByAllIndexesFromTable to avoid wasting lots of arrayLists; add todo about maybe only doing grouping if there is a mapped child table...

This commit is contained in:
2025-01-10 15:43:38 -06:00
parent 20332fa011
commit 70b569c2ca

View File

@ -55,6 +55,7 @@ public class TallRowsToRecord implements RowsToRecordInterface
private static final QLogger LOG = QLogger.getLogger(TallRowsToRecord.class); private static final QLogger LOG = QLogger.getLogger(TallRowsToRecord.class);
private Memoization<Pair<String, String>, Boolean> shouldProcesssAssociationMemoization = new Memoization<>(); private Memoization<Pair<String, String>, Boolean> shouldProcesssAssociationMemoization = new Memoization<>();
private Memoization<String, List<Integer>> groupByAllIndexesFromTableMemoization = new Memoization<>();
@ -96,6 +97,10 @@ public class TallRowsToRecord implements RowsToRecordInterface
continue; continue;
} }
///////////////////////////////////////////////////////////////////////////////
// maybe todo - some version of - only do this if there are mapped children? //
///////////////////////////////////////////////////////////////////////////////
if(rowsForCurrentRecord.isEmpty()) if(rowsForCurrentRecord.isEmpty())
{ {
/////////////////////////////////// ///////////////////////////////////
@ -154,8 +159,11 @@ public class TallRowsToRecord implements RowsToRecordInterface
***************************************************************************/ ***************************************************************************/
private List<Integer> groupByAllIndexesFromTable(BulkInsertMapping mapping, QTableMetaData table, BulkLoadFileRow headerRow, String name) throws QException private List<Integer> groupByAllIndexesFromTable(BulkInsertMapping mapping, QTableMetaData table, BulkLoadFileRow headerRow, String name) throws QException
{ {
Map<String, Integer> fieldIndexes = mapping.getFieldIndexes(table, name, headerRow); return ((groupByAllIndexesFromTableMemoization.getResult(table.getName(), (n) ->
return new ArrayList<>(fieldIndexes.values()); {
Map<String, Integer> fieldIndexes = mapping.getFieldIndexes(table, name, headerRow);
return new ArrayList<>(fieldIndexes.values());
})).orElse(null));
} }
@ -166,6 +174,7 @@ public class TallRowsToRecord implements RowsToRecordInterface
private QRecord makeRecordFromRows(QTableMetaData table, String associationNameChain, BulkInsertMapping mapping, BulkLoadFileRow headerRow, List<BulkLoadFileRow> rows) throws QException private QRecord makeRecordFromRows(QTableMetaData table, String associationNameChain, BulkInsertMapping mapping, BulkLoadFileRow headerRow, List<BulkLoadFileRow> rows) throws QException
{ {
QRecord record = new QRecord(); QRecord record = new QRecord();
record.setTableName(table.getName());
BulkLoadRecordUtils.addBackendDetailsAboutFileRows(record, CollectionUtils.useOrWrap(rows, new TypeToken<ArrayList<BulkLoadFileRow>>() {})); BulkLoadRecordUtils.addBackendDetailsAboutFileRows(record, CollectionUtils.useOrWrap(rows, new TypeToken<ArrayList<BulkLoadFileRow>>() {}));
Map<String, Integer> fieldIndexes = mapping.getFieldIndexes(table, associationNameChain, headerRow); Map<String, Integer> fieldIndexes = mapping.getFieldIndexes(table, associationNameChain, headerRow);
@ -273,6 +282,10 @@ public class TallRowsToRecord implements RowsToRecordInterface
break; break;
} }
///////////////////////////////////////////////////////////////////////////////
// maybe todo - some version of - only do this if there are mapped children? //
///////////////////////////////////////////////////////////////////////////////
List<Serializable> rowGroupByValues = getGroupByValues(row, groupByIndexes); List<Serializable> rowGroupByValues = getGroupByValues(row, groupByIndexes);
if(rowGroupByValues == null) if(rowGroupByValues == null)
{ {