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.
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
fix: duplicate read proto #1741
fix: duplicate read proto #1741
Changes from 4 commits
38fabe3
a84c6f3
6f28835
7bdfd60
f0c7193
136c805
a9f24cb
67eabde
8efe9c4
76d61dd
0811348
a1dff86
7a3f902
2134bd6
1db5a38
c011dd1
187ab41
202c544
f465172
852c0e9
da660a7
7ee194b
3a2d9f5
af2d812
File filter
Filter by extension
Conversations
Jump to
There are no files selected for viewing
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
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.
If cache is true, we should initialize it inside of
init
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.
And there is another issue, the first reading is called by ConfigReader::resource_reader, the second is called by ConfigReader::proto_reader, they are different object. So we need to get the HashMap from outside.
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.
How about using
Option<HashMap>
?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.
The cache should not be shared. If the cache needs to be shared, we should do that by sharing the ResourceReader.
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.
I think that's just an additional unwrapping that makes the code difficult to read. You can create two resource readers
Can we do something like above? We will know at compile time, if the reader is caching or not.
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.
Static dispatch is contagious, so I use the option to control whether enable cache.
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.
It makes the code a lot more modular, type-safe and easy to test. The current implementation has a lot of checks before reading, increasing the potential of bugs.
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.
I tried it, but got compile error about
not found self.resource_reader.read_file method of ProtoReader
. I'm not familiar with this, maybe I need a trait bound to help compiler?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.
Ok, I switch to static dispatch and add a reader trait.
Check warning on line 35 in src/resource_reader.rs
Codecov / codecov/patch
src/resource_reader.rs#L35
Check warning on line 44 in src/resource_reader.rs
Codecov / codecov/patch
src/resource_reader.rs#L44