feat/bust-cache-validators-change #14
No reviewers
Labels
No Label
Kind/Breaking
Kind/Bug
Kind/Documentation
Kind/Enhancement
Kind/Feature
Kind/Security
Kind/Testing
Priority
Critical
Priority
High
Priority
Low
Priority
Medium
Reviewed
Confirmed
Reviewed
Duplicate
Reviewed
Invalid
Reviewed
Won't Fix
Status
Abandoned
Status
Blocked
Status
Need More Info
No Milestone
No project
No Assignees
2 Participants
Due Date
No due date set.
Dependencies
No dependencies set.
Reference: numtide/treefmt#14
Loading…
Reference in New Issue
Block a user
No description provided.
Delete Branch "feat/bust-cache-validators-change"
Deleting a branch is permanent. Although the deleted branch may continue to exist for a short time before it actually gets removed, it CANNOT be undone in most cases. Continue?
Tracks the mod time and size of a formatter's executable in bolt.
The cache is busted using the following criteria:
Also implemented better resolution of symlinks when determining a formatters executable path.
Looks good 👍
I remember it taking me a bit of time getting these things so it feels right in the original implementation.
Random thought: for the formatted file paths, it might make sense to skip symlinks entirely. This removes the issue where treefmt could potentially format
/etc/passwd
because it's the target of a symlink in the repo. Repos really should only symlink to files that exist in the repo, and those are then also part of the Walking anyways.@ -69,0 +71,4 @@
// check for any newly configured or modified formatters
for name, formatter := range formatters {
stat, err := os.Lstat(formatter.Executable())
Probably we care more about which executable is running in case it's a symlink. I would use
os.Stat
here. And maybe store the resolved path as well?I went with
os.Lstat
here becausegofmt
resolved to a symlink which was then another relative symlink within the nix output path. This ensures we recursively resolve down to the underlying binary.For paths that are being formatted we already skip symlinks when traversing the filesystem
@ -69,0 +94,4 @@
entry = &Entry{
Size: stat.Size(),
Modified: stat.ModTime(),
}
This could be seen as a "CacheKey" or something like that. If any of the values have changed, invalidate. I know this is what you are doing already; just wondering about semantics a bit.
I currently think of it as a
cache.Entry
given the package it's within, as it's more of a Cache Entry for me than a Cache Key since it's not being used as the key in bolt.@ -110,12 +111,15 @@ func (f *Format) Run() error {
eg.Go(func() error {
batchSize := 1024
batch := make([]string, batchSize)
batch = batch[:0]
Aren't those two lines equivalent to
batch := []string{}
?What I believe I'm doing here is creating an instance of
batch
with a pre-initialised backing array ofbatchSize
but resetting the slice's length to 0 so that subsequent logic looking atlen(batch)
andrange batch
all work correctly.Looking at it with a debugger seems to confirm it's doing what I think it's doing, with the capacity being set to
1024
but length matching the latest batch to process.