Skip to content

Refactor MetadataProvider to improve table metadata retrieval logic#81

Merged
PhenX merged 3 commits intomainfrom
feature/dont-load-all-tables
Nov 1, 2025
Merged

Refactor MetadataProvider to improve table metadata retrieval logic#81
PhenX merged 3 commits intomainfrom
feature/dont-load-all-tables

Conversation

@PhenX
Copy link
Copy Markdown
Owner

@PhenX PhenX commented Oct 29, 2025

No description provided.

@PhenX PhenX requested a review from Copilot October 29, 2025 22:22
Copy link
Copy Markdown
Contributor

Copilot AI left a comment

Choose a reason for hiding this comment

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

Pull Request Overview

This PR refactors the MetadataProvider class to improve performance by implementing lazy loading for table metadata. Instead of pre-loading all entity types when a context is first accessed, the code now only creates TableMetadata on-demand for the specific entity type being requested.

Key changes:

  • Added readonly modifier to the _tablesPerContext field for immutability
  • Replaced eager loading of all entity types with lazy, on-demand loading
  • Simplified cache lookup logic by inverting the conditional check
  • Improved error message to be more specific about missing entity types

💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

throw new InvalidOperationException($"The type '{modelType.FullName}' is not part of the model for the current context.");
}

var provider = context.GetService<IBulkInsertProvider>();
Copy link

Copilot AI Oct 29, 2025

Choose a reason for hiding this comment

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

The IBulkInsertProvider service is retrieved inside the lock on every cache miss. Consider moving this retrieval outside the lock (after checking for cache miss but before the lock, or after the model type check) to reduce lock contention, as GetService<T>() is typically thread-safe.

Copilot uses AI. Check for mistakes.
fabien.menager added 2 commits October 30, 2025 18:13
# Conflicts:
#	src/PhenX.EntityFrameworkCore.BulkInsert/Metadata/MetadataProvider.cs
@PhenX PhenX merged commit d9546ce into main Nov 1, 2025
2 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants