Skip to content
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

Caching is important 🐌 #22261

Merged
merged 1 commit into from
Aug 27, 2020
Merged
Changes from all commits
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
17 changes: 12 additions & 5 deletions src/EFCore/ChangeTracking/Internal/StateManager.cs
Original file line number Diff line number Diff line change
Expand Up @@ -44,6 +44,8 @@ private readonly EntityReferenceMap _entityReferenceMap
private IIdentityMap _identityMap1;
private Dictionary<IKey, IIdentityMap> _identityMaps;
private bool _needsUnsubscribe;
private IChangeDetector _changeDetector;
private bool _changeDetectorInitialized;

private readonly IDiagnosticsLogger<DbLoggerCategory.ChangeTracking> _changeTrackingLogger;
private readonly IInternalEntityEntryFactory _internalEntityEntryFactory;
Expand Down Expand Up @@ -81,6 +83,7 @@ public StateManager([NotNull] StateManagerDependencies dependencies)

UpdateLogger = dependencies.UpdateLogger;
_changeTrackingLogger = dependencies.ChangeTrackingLogger;
_changeDetectorInitialized = false;
}

/// <summary>
Expand Down Expand Up @@ -987,10 +990,14 @@ public virtual void CascadeDelete(InternalEntityEntry entry, bool force, IEnumer
{
var doCascadeDelete = force || CascadeDeleteTiming != CascadeTiming.Never;
var principalIsDetached = entry.EntityState == EntityState.Detached;
var changeDetector = Context.ChangeTracker.AutoDetectChangesEnabled
&& (string)Context.Model[CoreAnnotationNames.SkipDetectChangesAnnotation] != "true"
? Context.GetDependencies().ChangeDetector
: null;
if (!_changeDetectorInitialized)
{
_changeDetector = Context.ChangeTracker.AutoDetectChangesEnabled
&& (string)Context.Model[CoreAnnotationNames.SkipDetectChangesAnnotation] != "true"
? Context.GetDependencies().ChangeDetector
: null;
_changeDetectorInitialized = true;
}

foreignKeys ??= entry.EntityType.GetReferencingForeignKeys();
foreach (var fk in foreignKeys)
Expand All @@ -1008,7 +1015,7 @@ public virtual void CascadeDelete(InternalEntityEntry entry, bool force, IEnumer
continue;
}

changeDetector?.DetectChanges(dependent);
_changeDetector?.DetectChanges(dependent);

if (dependent.EntityState != EntityState.Deleted
&& dependent.EntityState != EntityState.Detached
Expand Down