-
Notifications
You must be signed in to change notification settings - Fork 933
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
Optimize GetOrphans and remove wrong checks from IsNotTransientSlow #2056
Conversation
// 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; |
There was a problem hiding this comment.
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); |
There was a problem hiding this comment.
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)) |
There was a problem hiding this comment.
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
c78320a
to
99407a4
Compare
|
@bahusoid, could you please take a look at this:
if you have time? |
@maca88 seems like a bug in AsyncGenerator. I think AsyncGenerator should add nhibernate-core/src/NHibernate/Async/Collection/AbstractPersistentCollection.cs Lines 131 to 132 in 1006665
But it's not happening leading to warning (that treated as error):
Compilation error:
|
It is a bug, I've opened an issue for it. |
@fredericDelaporte could you please review this PR? |
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 viaGetEntityIdentifierIfNotUnsaved
. Removed hack that was introduced with NH607 (whenGetEntityIdentifierIfNotUnsaved
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 oldGetOrphans
implementation work.