fix: include max_file_size in S3 cache key to prevent stale digests#570
Open
Louiszk wants to merge 1 commit intocoderamp-labs:mainfrom
Open
fix: include max_file_size in S3 cache key to prevent stale digests#570Louiszk wants to merge 1 commit intocoderamp-labs:mainfrom
Louiszk wants to merge 1 commit intocoderamp-labs:mainfrom
Conversation
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.
This PR fixes a caching bug where S3 cache keys did not account for
max_file_size(see #568).Previously, if a repository was requested with the default 50KB limit, and then requested again with a 100MB limit, the server would return the cached 50KB version because the cache key only relied on include/exclude patterns and the commit hash.
generate_s3_file_pathinsrc/server/s3_utils.pyto acceptmax_file_sizeand append it to the hashing string.query.max_file_sizeinto both calls togenerate_s3_file_pathinsidesrc/server/query_processor.py.While looking into this, I realized this strict hashing approach might cause unnecessary cache misses. For example, if a user requests a 500KB limit, and then a 2MB limit on a repo where the largest file is only 100KB, the current fix will treat them as different keys and trigger a re-clone.
Ideally, the cache would stay the same in this instance. In the future, it might be worth adding
largest_file_encounteredto theS3MetadataJSON and updating the lookup logic to allow compatible cache hits.For now, adding the size to the hash key is a fast and reliable way to prevent the UI from serving incorrectly limited files.