Skip to content

Commit

Permalink
HHH-17983 Remove entity keys from batch queue before loading
Browse files Browse the repository at this point in the history
  • Loading branch information
mbladel committed Apr 24, 2024
1 parent c846bc3 commit 9346c28
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 11 deletions.
Expand Up @@ -134,6 +134,13 @@ protected void initializeEntities(
getLoadable().getEntityName(), id, Arrays.toString(idsToInitialize) );
}

for ( Object initializedId : idsToInitialize ) {
if ( initializedId != null ) {
// found or not, remove the key from the batch-fetch queue
removeBatchLoadableEntityKey( initializedId, getLoadable(), session );
}
}

LoaderHelper.loadByArrayParameter(
idsToInitialize,
sqlAst,
Expand All @@ -147,13 +154,6 @@ protected void initializeEntities(
readOnly,
session
);

for ( Object initializedId : idsToInitialize ) {
if ( initializedId != null ) {
// found or not, remove the key from the batch-fetch queue
removeBatchLoadableEntityKey( initializedId, getLoadable(), session );
}
}
}

@Override
Expand Down
Expand Up @@ -141,7 +141,6 @@ protected void initializeEntities(
);

final BatchFetchQueue batchFetchQueue = session.getPersistenceContextInternal().getBatchFetchQueue();
final List<EntityKey> entityKeys = arrayList( sqlBatchSize );

chunker.processChunks(
idsToInitialize,
Expand All @@ -166,7 +165,11 @@ protected void initializeEntities(
},
(key, relativePosition, absolutePosition) -> {
if ( key != null ) {
entityKeys.add( session.generateEntityKey( key, getLoadable().getEntityPersister() ) );
final EntityKey entityKey = session.generateEntityKey(
key,
getLoadable().getEntityPersister()
);
batchFetchQueue.removeBatchLoadableEntityKey( entityKey );
}
},
(startIndex) -> {
Expand All @@ -181,8 +184,6 @@ protected void initializeEntities(
}
},
(startIndex, nonNullElementCount) -> {
entityKeys.forEach( batchFetchQueue::removeBatchLoadableEntityKey );
entityKeys.clear();
},
session
);
Expand Down

0 comments on commit 9346c28

Please sign in to comment.