Skip to content

Eliminated double Persister resolution in Loader.InstanceNotYetLoaded flow #476

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 15 commits into from
Mar 23, 2019
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
12 changes: 6 additions & 6 deletions src/NHibernate/Async/Loader/Loader.cs
Original file line number Diff line number Diff line change
Expand Up @@ -740,9 +740,7 @@ private async Task InstanceAlreadyLoadedAsync(DbDataReader rs, int i, ILoadable
return;
}

var concretePersister = await (GetConcretePersisterAsync(rs, i, persister, key.Identifier, session, cancellationToken)).ConfigureAwait(false);
entry = entry ?? session.PersistenceContext.GetEntry(obj);
await (UpdateLazyPropertiesFromResultSetAsync(rs, i, obj, concretePersister, key, entry, persister, session, cacheBatchingHandler, cancellationToken)).ConfigureAwait(false);
await (UpdateLazyPropertiesFromResultSetAsync(rs, i, obj, key, entry, persister, session, cacheBatchingHandler, cancellationToken)).ConfigureAwait(false);
}

/// <summary>
Expand Down Expand Up @@ -781,8 +779,8 @@ private async Task<object> InstanceNotYetLoadedAsync(DbDataReader dr, int i, ILo
return obj;
}

private async Task UpdateLazyPropertiesFromResultSetAsync(DbDataReader rs, int i, object obj, ILoadable persister, EntityKey key,
EntityEntry entry, ILoadable rootPersister, ISessionImplementor session,
private async Task UpdateLazyPropertiesFromResultSetAsync(DbDataReader rs, int i, object obj, EntityKey key,
EntityEntry optionalEntry, ILoadable rootPersister, ISessionImplementor session,
Action<IEntityPersister, CachePutData> cacheBatchingHandler, CancellationToken cancellationToken)
{
cancellationToken.ThrowIfCancellationRequested();
Expand All @@ -794,6 +792,8 @@ private async Task UpdateLazyPropertiesFromResultSetAsync(DbDataReader rs, int i
return; // No lazy properties were loaded
}

var persister = await (GetConcretePersisterAsync(rs, i, rootPersister, key.Identifier, session, cancellationToken)).ConfigureAwait(false);
var entry = optionalEntry ?? session.PersistenceContext.GetEntry(obj);
// The property values will not be set when the entry status is Loading so in that case we have to get
// the uninitialized lazy properties from the loaded state
var uninitializedProperties = entry.Status == Status.Loading
Expand All @@ -817,7 +817,7 @@ private async Task UpdateLazyPropertiesFromResultSetAsync(DbDataReader rs, int i
? EntityAliases[i].SuffixedPropertyAliases
: GetSubclassEntityAliases(i, persister);

if (!await (persister.InitializeLazyPropertiesAsync(rs, id, obj, rootPersister, cols, updateLazyProperties, fetchAllProperties, session, cancellationToken)).ConfigureAwait(false))
if (!await (persister.InitializeLazyPropertiesAsync(rs, id, obj, cols, updateLazyProperties, fetchAllProperties, session, cancellationToken)).ConfigureAwait(false))
{
return;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -62,7 +62,7 @@ public virtual Task BindValuesAsync(DbCommand ps, CancellationToken cancellation
}

public Task InitializeLazyPropertiesAsync(
DbDataReader rs, object id, object entity, ILoadable rootPersister, string[][] suffixedPropertyColumns,
DbDataReader rs, object id, object entity, string[][] suffixedPropertyColumns,
string[] uninitializedLazyProperties, bool allLazyProperties, ISessionImplementor session, CancellationToken cancellationToken)
{
if (!HasLazyProperties)
Expand Down
3 changes: 1 addition & 2 deletions src/NHibernate/Async/Persister/Entity/ILoadable.cs
Original file line number Diff line number Diff line change
Expand Up @@ -73,7 +73,7 @@ public static Task<object[]> HydrateAsync(
/// </summary>
//6.0 TODO: Change to void and merge into ILoadable
internal static async Task<bool> InitializeLazyPropertiesAsync(
this ILoadable loadable, DbDataReader rs, object id, object entity, ILoadable rootPersister, string[][] suffixedPropertyColumns,
this ILoadable loadable, DbDataReader rs, object id, object entity, string[][] suffixedPropertyColumns,
string[] uninitializedLazyProperties, bool allLazyProperties, ISessionImplementor session, CancellationToken cancellationToken)
{
cancellationToken.ThrowIfCancellationRequested();
Expand All @@ -83,7 +83,6 @@ internal static async Task<bool> InitializeLazyPropertiesAsync(
rs,
id,
entity,
rootPersister,
suffixedPropertyColumns,
uninitializedLazyProperties,
allLazyProperties,
Expand Down
12 changes: 6 additions & 6 deletions src/NHibernate/Loader/Loader.cs
Original file line number Diff line number Diff line change
Expand Up @@ -1070,9 +1070,7 @@ private void InstanceAlreadyLoaded(DbDataReader rs, int i, ILoadable persister,
return;
}

var concretePersister = GetConcretePersister(rs, i, persister, key.Identifier, session);
entry = entry ?? session.PersistenceContext.GetEntry(obj);
UpdateLazyPropertiesFromResultSet(rs, i, obj, concretePersister, key, entry, persister, session, cacheBatchingHandler);
UpdateLazyPropertiesFromResultSet(rs, i, obj, key, entry, persister, session, cacheBatchingHandler);
}

private void CacheByUniqueKey(int i, IEntityPersister persister, object obj, ISessionImplementor session, bool alreadyLoaded)
Expand Down Expand Up @@ -1159,8 +1157,8 @@ private HashSet<string> GetFetchLazyProperties(int i)
return array?[i];
}

private void UpdateLazyPropertiesFromResultSet(DbDataReader rs, int i, object obj, ILoadable persister, EntityKey key,
EntityEntry entry, ILoadable rootPersister, ISessionImplementor session,
private void UpdateLazyPropertiesFromResultSet(DbDataReader rs, int i, object obj, EntityKey key,
EntityEntry optionalEntry, ILoadable rootPersister, ISessionImplementor session,
Action<IEntityPersister, CachePutData> cacheBatchingHandler)
{
var fetchAllProperties = IsEagerPropertyFetchEnabled(i);
Expand All @@ -1171,6 +1169,8 @@ private void UpdateLazyPropertiesFromResultSet(DbDataReader rs, int i, object ob
return; // No lazy properties were loaded
}

var persister = GetConcretePersister(rs, i, rootPersister, key.Identifier, session);
var entry = optionalEntry ?? session.PersistenceContext.GetEntry(obj);
// The property values will not be set when the entry status is Loading so in that case we have to get
// the uninitialized lazy properties from the loaded state
var uninitializedProperties = entry.Status == Status.Loading
Expand All @@ -1194,7 +1194,7 @@ private void UpdateLazyPropertiesFromResultSet(DbDataReader rs, int i, object ob
? EntityAliases[i].SuffixedPropertyAliases
: GetSubclassEntityAliases(i, persister);

if (!persister.InitializeLazyProperties(rs, id, obj, rootPersister, cols, updateLazyProperties, fetchAllProperties, session))
if (!persister.InitializeLazyProperties(rs, id, obj, cols, updateLazyProperties, fetchAllProperties, session))
{
return;
}
Expand Down
2 changes: 1 addition & 1 deletion src/NHibernate/Persister/Entity/AbstractEntityPersister.cs
Original file line number Diff line number Diff line change
Expand Up @@ -1395,7 +1395,7 @@ public virtual object InitializeLazyProperty(string fieldName, object entity, IS
}

public void InitializeLazyProperties(
DbDataReader rs, object id, object entity, ILoadable rootPersister, string[][] suffixedPropertyColumns,
DbDataReader rs, object id, object entity, string[][] suffixedPropertyColumns,
string[] uninitializedLazyProperties, bool allLazyProperties, ISessionImplementor session)
{
if (!HasLazyProperties)
Expand Down
3 changes: 1 addition & 2 deletions src/NHibernate/Persister/Entity/ILoadable.cs
Original file line number Diff line number Diff line change
Expand Up @@ -107,7 +107,7 @@ public static object[] Hydrate(
/// </summary>
//6.0 TODO: Change to void and merge into ILoadable
internal static bool InitializeLazyProperties(
this ILoadable loadable, DbDataReader rs, object id, object entity, ILoadable rootPersister, string[][] suffixedPropertyColumns,
this ILoadable loadable, DbDataReader rs, object id, object entity, string[][] suffixedPropertyColumns,
string[] uninitializedLazyProperties, bool allLazyProperties, ISessionImplementor session)
{
if (loadable is AbstractEntityPersister abstractEntityPersister)
Expand All @@ -116,7 +116,6 @@ internal static bool InitializeLazyProperties(
rs,
id,
entity,
rootPersister,
suffixedPropertyColumns,
uninitializedLazyProperties,
allLazyProperties,
Expand Down