Skip to content
This repository has been archived by the owner on Oct 27, 2020. It is now read-only.

feat: add option for custom compare function #71

Conversation

lellimecnar
Copy link

It's not always reliable to use mtime, so allowing for a compare function to be passed makes it possible for custom logic to be used. (ie. hashing)

This PR contains a:

  • bugfix
  • new feature
  • code refactor
  • test update
  • typo fix
  • metadata update

Motivation / Use-Case

In our CI environment, the mtime doesn't always match when it probably should, so we'd like to use something else (like file hashing). This is a simple update to expose a compare option that can be used to provide custom logic.

It's been mentioned before (#34 #41 #29)

Breaking Changes

No breaking changes

Additional Info

I started writing some tests, but I'm not sure how best to test this update...

@jsf-clabot
Copy link

jsf-clabot commented Apr 20, 2019

CLA assistant check
All committers have signed the CLA.

@codecov
Copy link

codecov bot commented Apr 20, 2019

Codecov Report

Merging #71 into master will decrease coverage by 0.88%.
The diff coverage is 0%.

Impacted file tree graph

@@            Coverage Diff             @@
##           master      #71      +/-   ##
==========================================
- Coverage   58.13%   57.25%   -0.89%     
==========================================
  Files           2        2              
  Lines         129      131       +2     
  Branches       20       20              
==========================================
  Hits           75       75              
- Misses         46       48       +2     
  Partials        8        8
Impacted Files Coverage Δ
src/index.js 57.69% <0%> (-0.91%) ⬇️

Continue to review full report at Codecov.

Legend - Click here to learn more
Δ = absolute <relative> (impact), ø = not affected, ? = missing data
Powered by Codecov. Last update 1369c05...0c10211. Read the comment docs.

@codecov
Copy link

codecov bot commented Apr 20, 2019

Codecov Report

Merging #71 into master will decrease coverage by 0.88%.
The diff coverage is 0%.

Impacted file tree graph

@@            Coverage Diff             @@
##           master      #71      +/-   ##
==========================================
- Coverage   57.81%   56.92%   -0.89%     
==========================================
  Files           2        2              
  Lines         128      130       +2     
  Branches       20       20              
==========================================
  Hits           74       74              
- Misses         46       48       +2     
  Partials        8        8
Impacted Files Coverage Δ
src/index.js 57.36% <0%> (-0.91%) ⬇️

Continue to review full report at Codecov.

Legend - Click here to learn more
Δ = absolute <relative> (impact), ø = not affected, ? = missing data
Powered by Codecov. Last update 1bdf3e6...66f90c7. Read the comment docs.

@alexander-akait
Copy link
Member

/cc @mistic

@m2bright
Copy link

👍

@lellimecnar
Copy link
Author

lellimecnar commented Apr 30, 2019

We have discovered why the mtime is unreliable in our environment:

By default, some tools (like tar) preserve mtimes that are precise to the second not the millisecond. Since the cache-loader is using === to compare mtimes, this causes some environments (like CI) to always invalidate the cache.

So, I've updated the default compare function to ignore milliseconds, which should solve the issue for these types of environments.

Once this PR is merged, I would be happy to create another PR that exposes a precision option that would allow this to be configured.

@mistic
Copy link
Collaborator

mistic commented May 3, 2019

@lellimecnar I think removing the miliseconds part should not be the default, what happens if while developing there are 2 different changes to the same file within the same second? I think we should open 2 different PRs, one for simply provide a configurable compare function that receives 2 times and a second one to change the precision of the times passed to the compare function. The default should be the entire time with miliseconds too

What do u think @evilebottnawi ?

@lellimecnar
Copy link
Author

I can see that @mistic. I'll make that change, and start the other PR.

@lellimecnar
Copy link
Author

@mistic this PR has been updated

@lellimecnar
Copy link
Author

@mistic Here is the PR for the precision option: #73

mistic
mistic previously approved these changes May 28, 2019
Copy link
Collaborator

@mistic mistic left a comment

Choose a reason for hiding this comment

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

LGTM but I think we should add tests

@mistic
Copy link
Collaborator

mistic commented May 28, 2019

@lellimecnar also can you solve the conflicts and merge with master please?

It's not always reliable to use `mtime`, so allowing for a `compare` function to be passed makes it possible for custom logic to be used. (ie. hashing)
@mistic
Copy link
Collaborator

mistic commented May 30, 2019

Closed as it will be merged through #71 with tests.

@mistic mistic closed this May 30, 2019
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

5 participants