Skip to content

Optimize GetOrphans and remove wrong checks from IsNotTransientSlow #2056

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
Oct 20, 2019

Conversation

bahusoid
Copy link
Member

@bahusoid bahusoid commented Mar 13, 2019

  • Removed possibly slow transient check for current items (it's enough to have defined ID for orphan check). Made GetOrphans method not async.

  • Made use directly persister.GetIdentifier instead of additional session based checks via GetEntityIdentifierIfNotUnsaved. Removed hack that was introduced with NH607 (when GetEntityIdentifierIfNotUnsaved returns null as ID for not-null transient entity instead of throwing exception)

  • Removed wrong checks from IsNotTransientSlow that it seems were added specifically to make old GetOrphans implementation work.

// i'm not secure that NH607 is a test for a right behavior
EntityEntry entry = session.PersistenceContext.GetEntry(entity);
if (entry != null)
return entry.Id;
Copy link
Member Author

@bahusoid bahusoid Mar 14, 2019

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

PersistenceContext can contain transient objects in state Saving during flush. This hack was added (that returns null ID for transient object) to make GetOrphans work. Removing it as GetOrphans is not relying on GetEntityIdentifierIfNotUnsaved anymore.

{
object currentId = ForeignKeys.GetEntityIdentifierIfNotUnsaved(entityName, current, session);
Copy link
Member Author

@bahusoid bahusoid Mar 14, 2019

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This call checks session entry dictionary and throw exception for transient object. This exception doesn't make any sense for orphans detection. So let's call persister.GetIdentifier (currently wrapped to ForeignKeys.GetIdentifier to support proxy) directly without any additional checks

foreach (object current in currentElements)
{
if (current != null && ForeignKeys.IsNotTransientSlow(entityName, current, session))
Copy link
Member Author

@bahusoid bahusoid Mar 14, 2019

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Transient check is not really required for orphan detection. So remove it as potentially slow

@bahusoid bahusoid changed the title WIP Optimize GetOrphans and remove wrong checks from IsNotTransientSlow Optimize GetOrphans and remove wrong checks from IsNotTransientSlow Apr 5, 2019
hazzik
hazzik previously approved these changes Apr 26, 2019
@hazzik
Copy link
Member

hazzik commented Jun 1, 2019

GetOrphans is still async in PersistentArrayHolder.

@hazzik
Copy link
Member

hazzik commented Jun 17, 2019

@bahusoid, could you please take a look at this:

GetOrphans is still async in PersistentArrayHolder.

if you have time?

@bahusoid
Copy link
Member Author

bahusoid commented Jun 17, 2019

@maca88 seems like a bug in AsyncGenerator. I think AsyncGenerator should add Obsolete attribute for abstract method overrides with Obsolete attribute:

[Obsolete("This method has no more usages and will be removed in a future version")]
public abstract Task<ICollection> GetOrphansAsync(object snapshot, string entityName, CancellationToken cancellationToken);

But it's not happening leading to warning (that treated as error):
public override Task<ICollection> GetOrphansAsync(object snapshot, string entityName, CancellationToken cancellationToken)

Compilation error:

Async/Collection/PersistentArrayHolder.cs(30,37): error CS0672: Member 'PersistentArrayHolder.GetOrphansAsync(object, string, CancellationToken)' overrides obsolete member 'AbstractPersistentCollection.GetOrphansAsync(object, string, CancellationToken)'. Add the Obsolete attribute to 'PersistentArrayHolder.GetOrphansAsync(object, string, CancellationToken)'. [/home/travis/build/nhibernate/nhibernate-core/src/NHibernate/NHibernate.csproj]

@maca88
Copy link
Contributor

maca88 commented Jun 17, 2019

It is a bug, I've opened an issue for it.

@hazzik
Copy link
Member

hazzik commented Oct 15, 2019

@fredericDelaporte could you please review this PR?

@fredericDelaporte fredericDelaporte self-requested a review October 17, 2019 19:12
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants