Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add hashGlobs query to state service #3484

Merged
merged 16 commits into from
Sep 13, 2024
Merged

Add hashGlobs query to state service #3484

merged 16 commits into from
Sep 13, 2024

Conversation

MDrakos
Copy link
Member

@MDrakos MDrakos commented Sep 9, 2024

TaskDX-3032 We have a query on the state-svc for calculating a hash for a series of globs

@MDrakos MDrakos changed the base branch from master to version/0-47-0-RC1 September 9, 2024 22:33
@MDrakos
Copy link
Member Author

MDrakos commented Sep 9, 2024

When I ran state run generate-graph the generated code was using types that weren't present in our dependencies. I've update the gqlgen dependency to match that of the gqlgen tool that is installed by generate-graph. That is why there are so many vendor changes.

"time"

"github.com/ActiveState/cli/internal/errs"
"github.com/cespare/xxhash"
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

xxhash is a fast hash algorithm. For more info see here: https://xxhash.com/
this link is safe for work

@MDrakos MDrakos requested a review from Naatan September 10, 2024 20:07
@MDrakos MDrakos marked this pull request as ready for review September 10, 2024 20:07
.github/workflows/build.yml Outdated Show resolved Hide resolved
internal/hash/file_hasher.go Outdated Show resolved Hide resolved
internal/hash/file_hasher.go Outdated Show resolved Hide resolved
internal/hash/file_hasher.go Outdated Show resolved Hide resolved
}

fh.cache.Set(cacheKey(file.Name(), fileInfo.ModTime()), hash, cache.NoExpiration)
fmt.Fprintf(hasher, "%x", hash)
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

What does this do? Might need a comment, or drop if it's for debugging.

Copy link
Member Author

@MDrakos MDrakos Sep 12, 2024

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Added a comment. The hasher is an io.Writer so this is writing the hash of the current file to the overall hash.

fmt.Fprintf(hasher, "%x", hash)
}

return base64.StdEncoding.EncodeToString(hasher.Sum(nil)), nil
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Does the hasher itself not produce a usable string?

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

hasher.Sum() returns a slice of bytes and I don't believe these values are guaranteed to be printable characters. They could be control characters or invalid UFT-8 sequences. The encoding ensures that the output is safe to print and transmit.

@MDrakos MDrakos requested a review from Naatan September 12, 2024 21:04
cmd/state-svc/internal/hash/file_hasher.go Outdated Show resolved Hide resolved
}
}

func (fh *FileHasher) HashFiles(files []string) (string, error) {
func (fh *FileHasher) HashFiles(files []string) (hash string, rerr error) {
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
func (fh *FileHasher) HashFiles(files []string) (hash string, rerr error) {
func (fh *FileHasher) HashFiles(files []string) (string, error) {

Doesn't look like naming these is used for anything. And it can actually cause bug so better to avoid.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

ah I see. In that case I suggest renaming hash to _, so it doesn't clash with your code. You are using a hash var in the function body. I don't think it clashes as currently written, but it feels error-prone.

@MDrakos MDrakos requested a review from Naatan September 13, 2024 20:47
}
}

func (fh *FileHasher) HashFiles(files []string) (string, error) {
func (fh *FileHasher) HashFiles(files []string) (hash string, rerr error) {
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

ah I see. In that case I suggest renaming hash to _, so it doesn't clash with your code. You are using a hash var in the function body. I don't think it clashes as currently written, but it feels error-prone.

@MDrakos MDrakos requested a review from Naatan September 13, 2024 21:47
@MDrakos MDrakos merged commit 46bf5c6 into version/0-47-0-RC1 Sep 13, 2024
7 of 8 checks passed
@MDrakos MDrakos deleted the DX-3032 branch September 13, 2024 22:22
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants