Fix LiteFileStream.SetReadStreamPosition#2459
Conversation
|
What version can use this fix? |
Looking at the git blame, should be valid for basically any version from the last five years or so, though you'd have to apply the commit from my branch to that version. There's no released version with it, so no matter what you'd have to build it yourself. |
| int loadedChunk = _currentChunkIndex; | ||
| int newChunkIndex = 0; | ||
| while (seekStreamPosition <= _streamPosition) { | ||
| if (!_chunkLengths.ContainsKey(newChunkIndex)) { |
There was a problem hiding this comment.
Missing an opportunity of using trygetvalue ;)
|
I would like to see some unitttests for this pr as i currently don't fully understand the issue. |
| private byte[] _currentChunkData = null; | ||
| private int _positionInChunk = 0; | ||
| private MemoryStream _buffer; | ||
| private Dictionary<int, long> _chunkLengths = new Dictionary<int, long>(); |
There was a problem hiding this comment.
Not trying to force you change this, but are you sure sure separating fields from their main use is a good idea? I mean if it would be used by many different partials, this would imo the best place but you are only using it in the .Read partial.
What do you think? Does that make sense?
There was a problem hiding this comment.
Not a big deal to me, whatever works best with the style for the repository.
| seekStreamPosition += _currentChunkData.Length; | ||
| } | ||
| newChunkIndex++; | ||
| } |
There was a problem hiding this comment.
While you are at it, add a new line here
|
Thank you for your contribution and bearing with me :D |
Fix for issue #2458. Not a great solution, since it makes seeking much more expensive, but it works in my situation. I don't think there's a way to make it significantly faster without making chunks uniform length, which would require changes on the write side and not work for existing databases.