[caching] save/load source hierarchy and extracted log statements#20
Open
tstack wants to merge 7 commits intottiimm:mainfrom
Open
[caching] save/load source hierarchy and extracted log statements#20tstack wants to merge 7 commits intottiimm:mainfrom
tstack wants to merge 7 commits intottiimm:mainfrom
Conversation
Scanning the source hierarchy and extracting log statements
is pretty costly, so we need to cache what we found between
runs. This change writes a separate file for every source
root. The file contains a header that is a JSON-line with
interesting metadata that a user might find helpful. The
body of the file is a bincode serialization of the
SourceTree object. The CLI will try to load from the cache
on startup, check for any changes in the source tree, and
then update the cache, if necessary.
I was originally looking at using SQLite for the cache, but
it's hard to write blobs of unknown size to a table. This
approach seems to work since the header can easily be read
separately from the main content to determine if the file
is valid or not. I also tried using the postcard
serializer, but had trouble getting it to work. The
bincode one seems to just work.
Files:
* Cargo.toml: Add some more dependencies:
- bincode for serialization
- directories for finding the user's platform-specific
cache directory
- serde_regex for serializing/deserializing Regex
- sha2 for producing a hash used for the cache file names
- tempfile for creating the cache file
- walkdir for walking the cache dir in the tests
* cache-header-v1.json: The schema for the cache entry
header
* lib.rs: Add cache stuff
* main.rs: Add a footer to the help to mention where the
cache is. Load the statements from the cache and save
for future use.
* source_hier.rs: Derive `Deserialize` on various structs.
* common_settings/mod.rs: Move helper module to its own
directory.
* source_ref.rs: Serialize/deserialize the Regex directly
so the deserialize can fail if the regex string is
invalid. Add separate `pattern_str` to cache the
string version of the pattern.
If running with "-v", log that the cache will not be used
ttiimm
approved these changes
Oct 29, 2025
| cmd.env("XDG_CONFIG_HOME", self.location.path()); | ||
| cmd.env("USERPROFILE", self.location.path()); | ||
| cmd.env("LOCALAPPDATA", self.location.path()); | ||
| cmd.env("APPDATA", self.location.path()); |
Owner
There was a problem hiding this comment.
Does ProjectDirs need TEMP or TMP set to work on windows? That was one recommendation by the coding assistant on how to fix this...
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.
Scanning the source hierarchy and extracting log statements is pretty costly, so we need to cache what we found between runs. This change writes a separate file for every source root. The file contains a header that is a JSON-line with interesting metadata that a user might find helpful. The body of the file is a bincode serialization of the SourceTree object. The CLI will try to load from the cache on startup, check for any changes in the source tree, and then update the cache, if necessary.
I was originally looking at using SQLite for the cache, but it's hard to write blobs of unknown size to a table. This approach seems to work since the header can easily be read separately from the main content to determine if the file is valid or not. I also tried using the postcard
serializer, but had trouble getting it to work. The bincode one seems to just work.
Files:
Deserializeon various structs.pattern_strto cache the string version of the pattern.