disqus / grunt-smartrev

A "smart" file versioner for production environments which takes inter-file dependencies into account automatically.
Apache License 2.0
75 stars 6 forks source link

Add a custom salt option for hash generation #15

Closed BYK closed 7 years ago

BYK commented 7 years ago

This allows mass changing hashes when something goes wrong.

Digikid13 commented 7 years ago

👀

Munter commented 7 years ago

I just looked through your source code, since normally nothing should go wrong with content addressable hashing. I think I saw something that might explain why the hashing might be off some times.

Your tree traversal algorithm is a loop sorted ascending by incoming relations length. This is along the right lines, but still leaves room for error in ordering. The correct algorithm to traverse the tree is starting at the entry points, usually HTML, and do a depth first post-order traversal. This gives you a guarantee of having hashed all children before any of their containing parents.

I think such a change might completely remove the need for a cache buster option like this one.

Here is our traversal algorithm in assetgraph for reference: https://github.com/assetgraph/assetgraph/blob/master/lib/index.js#L520-L537

BYK commented 7 years ago

@Munter we are doing a depth-first post-order. I think our tanglement with Grunt and allowing multiple entry points masks that.

The reason we need a cache busting system like this is because recently CloudFlare messed some of our PNG images and since they almost never change, we need to invalidate the hashses to break infinite caching.

Munter commented 7 years ago

Oh dear... Never mind me then :)