Fix O(n) ChangeTracker full scan in DomainEventScraper (#2476)#2484
Merged
jeremydmiller merged 2 commits intomainfrom Apr 9, 2026
Merged
Fix O(n) ChangeTracker full scan in DomainEventScraper (#2476)#2484jeremydmiller merged 2 commits intomainfrom
jeremydmiller merged 2 commits intomainfrom
Conversation
…tch inserts Replace individual DbContext.Add calls in the Wolverine-enabled path of PersistOutgoingAsync(Envelope[]) with a single DbContext.AddRange call, allowing providers like Npgsql to batch INSERT statements into a single round-trip. Adds an integration test verifying all envelopes in the batch are correctly persisted. Fixes #2475. Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
…ed states only (#2476) Before this change, DomainEventScraper<T, TEvent>.ScrapeEvents() iterated every tracked entity in the ChangeTracker regardless of state. Domain events can only originate from entities whose state is Added or Modified, so scanning Unchanged and Deleted entries is wasted work. Added Microsoft.EntityFrameworkCore.InMemory to EfCoreTests so the new unit tests can run without SQL Server infrastructure. Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
This was referenced Apr 11, 2026
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
Fixes #2476.
DomainEventScraper<T, TEvent>.ScrapeEvents()previously calledChangeTracker.Entries()and iterated every tracked entity before filtering down to the target type. In DbContexts that track many entities this is an unnecessary O(n) scan.EntityStatebeforeOfType<T>()– onlyAddedandModifiedentries can have domain events, soUnchangedandDeletedentries are now skipped up-front.Microsoft.EntityFrameworkCore.InMemorytoEfCoreTeststo support infrastructure-free unit tests.DomainEventScraperStateFilterTestswith two tests that verify onlyAdded/Modifiedentities are considered by the scraper — including a case where anUnchangedentity has domain events artificially injected, confirming they are intentionally skipped.Test plan
EfCoreTests/DomainEvents/DomainEventScraperStateFilterTests.cspass without any infrastructure (InMemory provider)configuration_of_domain_events_scraperscontinue to pass🤖 Generated with Claude Code