Fix: cache Repository instances per file path in GetRepository()#27
Open
HashidaTKS wants to merge 1 commit intomasterfrom
Open
Fix: cache Repository instances per file path in GetRepository()#27HashidaTKS wants to merge 1 commit intomasterfrom
HashidaTKS wants to merge 1 commit intomasterfrom
Conversation
…stantiation GetRepository() was creating a new Repository instance on every call, meaning multiple instances could exist for the same file path. This undermines instance-level locking and wastes memory. Use ConcurrentDictionary.GetOrAdd to ensure each file path maps to exactly one Repository instance throughout the application lifetime. Applied to: BetInformation, ActualRaceAndOddsData, TheoreticalRaceAndOddsData, RaceResult Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
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.
問題点
BetInformation.GetRepository()、ActualRaceAndOddsData.GetRepository()、TheoreticalRaceAndOddsData.GetRepository()、RaceResult.GetRepository()のいずれも呼び出し毎にnew Repository(path)でインスタンスを生成していた。同一ファイルパスに対して複数のインスタンスが存在するため:
lock(this)が機能せず、並行アクセス時にデータ競合が発生しうるXmlSerializerWrapperやディレクトリ作成が実行され、不要なオーバーヘッドが発生する改善内容
各モデルクラスに
ConcurrentDictionary<string, TRepository> _repositoryCacheを追加し、GetOrAddで同一パスには同一インスタンスを返すよう修正。対象:
BetInformationActualRaceAndOddsDataTheoreticalRaceAndOddsDataRaceResultTest plan
RaceDataに対してGetRepository()を複数回呼び出した場合、同じインスタンスが返ることを確認RaceDataに対しては別インスタンスが返ることを確認🤖 Generated with Claude Code