8000 bug #21458 [Config] Early return for DirectoryResource (robfrawley) · symfony/symfony@2c302ce · GitHub
[go: up one dir, main page]

Skip to content

Commit 2c302ce

Browse files
committed
bug #21458 [Config] Early return for DirectoryResource (robfrawley)
This PR was squashed before being merged into the 2.7 branch (closes #21458). Discussion ---------- [Config] Early return for DirectoryResource | Q | A | ------------- | --- | Branch? | 2.7 | Bug fix? | yes | New feature? | sure? | BC breaks? | no | Deprecations? | no | Tests pass? | no | Fixed tickets | | Related PRs | #21440 | License | MIT | Doc PR | n/a Alternate PR that implements an early return for `DirectoryResource` to increase the speed on large file sets. We can never return early with `true` without checking all assets within the resource, as the aforementioned referenced PR did; hence this PR takes the counter approach and returns `false` early where appropriate. _Conversation about possible bug at #21458 (comment) Commits ------- d5746ec fix directory resource considers same timestamp not fresh 96107e2 return false early from directory resource
2 parents e7541d9 + d5746ec commit 2c302ce

File tree

2 files changed

+12
-4
lines changed

2 files changed

+12
-4
lines changed

src/Symfony/Component/Config/Resource/DirectoryResource.php

Lines changed: 9 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -68,7 +68,10 @@ public function isFresh($timestamp)
6868
return false;
6969
}
7070

71-
$newestMTime = filemtime($this->resource);
71+
if ($timestamp < filemtime($this->resource)) {
72+
return false;
73+
}
74+
7275
foreach (new \RecursiveIteratorIterator(new \RecursiveDirectoryIterator($this->resource), \RecursiveIteratorIterator::SELF_FIRST) as $file) {
7376
// if regex filtering is enabled only check matching files
7477
if ($this->pattern && $file->isFile() && !preg_match($this->pattern, $file->getBasename())) {
@@ -81,10 +84,13 @@ public function isFresh($timestamp)
8184
continue;
8285
}
8386

84-
$newestMTime = max($file->getMTime(), $newestMTime);
87+
// early return if a file's mtime exceeds the passed timestamp
88+
if ($timestamp < $file->getMTime()) {
89+
return false;
90+
}
8591
}
8692

87-
return $newestMTime < $timestamp;
93+
return true;
8894
}
8995

9096
public function serialize()

src/Symfony/Component/Config/Tests/Resource/DirectoryResourceTest.php

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -96,8 +96,10 @@ public function testIsFreshNewFileWithDifferentPattern()
9696
public function testIsFreshDeleteFile()
9797
{
9898
$resource = new DirectoryResource($this->directory);
99+
$time = time();
100+
sleep(1);
99101
unlink($this->directory.'/tmp.xml');
100-
$this->assertFalse($resource->isFresh(time()), '->isFresh() returns false if an existing file is removed');
102+
$this->assertFalse($resource->isFresh($time), '->isFresh() returns false if an existing file is removed');
101103
}
102104

103105
public function testIsFreshDeleteDirectory()

0 commit comments

Comments
 (0)
0