-
Notifications
You must be signed in to change notification settings - Fork 234
Timestamp returned for trait last modification times in the cached reader should be an integer, is an array #105
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
Timestamp returned for trait last modification times in the cached reader should be an integer, is an array #105
Conversation
@trsteel88 Thanks. |
/** | ||
* @param ReflectionClass $reflectionTrait | ||
* @return int | ||
*/ | ||
private function getTraitLastModificationTimes(ReflectionClass $reflectionTrait) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
the name should be changed, as it does not return several times anymore
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This method returns an int[]
, which is then passed to max()
in private function getLastModification()
. If I get it correctly, the fix is different, and it is to change that function's body instead:
return max(array_merge(
[$filename ? filemtime($filename) : 0],
// notice the three dots:
...array_map([$this, 'getTraitLastModificationTimes'], $class->getTraits()),
array_map([$this, 'getLastModification'], $class->getInterfaces()),
$parent ? [$this->getLastModification($parent)] : []
));
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The three dots don't work.
Compile Error: Cannot use positional argument after argument unpacking
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
A test case demonstrating the current issue is also needed.
/** | ||
* @param ReflectionClass $reflectionTrait | ||
* @return int | ||
*/ | ||
private function getTraitLastModificationTimes(ReflectionClass $reflectionTrait) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This method returns an int[]
, which is then passed to max()
in private function getLastModification()
. If I get it correctly, the fix is different, and it is to change that function's body instead:
return max(array_merge(
[$filename ? filemtime($filename) : 0],
// notice the three dots:
...array_map([$this, 'getTraitLastModificationTimes'], $class->getTraits()),
array_map([$this, 'getLastModification'], $class->getInterfaces()),
$parent ? [$this->getLastModification($parent)] : []
));
@Ocramius @mikeSimonson where should this test go? I can't see any existing tests for the CachedReacher class. I'm assuming we just need a single test to ensure that getLastModification returns an int (and never an array)? |
@trsteel88 The test should go there with the other tests of cachedReader. |
Thanks @mikeSimonson - I'll add one in. Also, I noticed that within fetchFromCache() it has the following:
In dev, debug is always going to be false. This is rendering the cache completely useless. Is this meant to be there? |
In dev mode, caches should really not be hit at all, so that's intentional. |
…t modification should be an integer value
…t modification should be an integer value
@trsteel88 merged, I added a test to it :-) |
This caused the error in #117 =/ |
@chosroes I still need a test case for that - can't do anything without it, and I'm not bootstrapping a symfony application for that. |
This PR fixes an issue where the cache is constantly being written - wasting IO.
After looking into this further, I found that the problem I'm having with excessive IO is because getLastModification is merging the timestamps incorrectly.
The result of the following can't be merged:
The result of this is that it can't work out the max() of the traits.
To resolve this, I updated getTraitLastModificationTimes to always return the max timestamp.
Using this PR in favour of another change I made: #104