feat(common): Introduce Chunk::lazy_previous
in the LinkedChunk
#4675
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.
This patch introduces
Chunk::lazy_previous
which is a key feature to support lazy-loading of aLinkedChunk
. When a chunk is loaded, if it is the first, it keeps in memory whether it has a previous chunk or not. Thus, it is possible to insert new chunk in front of theLinkedChunk
, andUpdate
s will correctly continue to link chunks between them (withNewItemsChunk
andNewGapChunk
).Example, imagine the following chunks: [0] <-> [1] <-> [2]. If [2] is the only one being loaded. Then its previous chunk, [1], is loaded from the store (because [2]'s previous is [1] in the store). Then [1] is replaced by [3] and [4]. We get this: [4] <-> [3] <-> [1] <-> [2]. If the
Update::New*Chunk
for [4] doesn't contain aprevious
, the store is out of sync: in the store, [4] has no previous, but [0] still has [1] for itsnext
.With this
lazy_previous
, the links are correctly computed.EventCache
storage #3280EventCache
lazy-loading #4632