Skip to content

Commit

Permalink
Merge pull request nextcloud#8714 from nextcloud/8705
Browse files Browse the repository at this point in the history
Check if the cached js file exists
  • Loading branch information
MorrisJobke authored Mar 7, 2018
2 parents d1aa96f + 448a5e5 commit 8d86548
Show file tree
Hide file tree
Showing 2 changed files with 25 additions and 1 deletion.
9 changes: 8 additions & 1 deletion lib/private/Template/JSCombiner.php
Original file line number Diff line number Diff line change
Expand Up @@ -104,13 +104,20 @@ public function process($root, $file, $app) {
* @return bool
*/
protected function isCached($fileName, ISimpleFolder $folder) {
$fileName = str_replace('.json', '.js', $fileName) . '.deps';
$fileName = str_replace('.json', '.js', $fileName);

if (!$folder->fileExists($fileName)) {
return false;
}

$fileName = $fileName . '.deps';
try {
$deps = $this->depsCache->get($folder->getName() . '-' . $fileName);
if ($deps === null || $deps === '') {
$depFile = $folder->getFile($fileName);
$deps = $depFile->getContent();
}

// check again
if ($deps === null || $deps === '') {
$this->logger->info('JSCombiner: deps file empty: ' . $fileName);
Expand Down
17 changes: 17 additions & 0 deletions tests/lib/Template/JSCombinerTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -187,6 +187,10 @@ public function testProcessCachedFile() {

$fileDeps->expects($this->once())->method('getContent')->willReturn('{}');

$folder->method('fileExists')
->with('combine.js')
->willReturn(true);

$folder->method('getFile')
->will($this->returnCallback(function($path) use ($file, $fileDeps) {
if ($path === 'combine.js') {
Expand All @@ -196,6 +200,7 @@ public function testProcessCachedFile() {
if ($path === 'combine.js.deps') {
return $fileDeps;
}

$this->fail();
}));

Expand All @@ -221,6 +226,9 @@ public function testProcessCachedFileMemcache() {
->willReturn($folder);
$folder->method('getName')
->willReturn('awesomeapp');
$folder->method('fileExists')
->with('combine.js')
->willReturn(true);

$file = $this->createMock(ISimpleFile::class);

Expand Down Expand Up @@ -263,6 +271,9 @@ public function testIsCachedNoDepsFile() {
public function testIsCachedWithNotExistingFile() {
$fileName = 'combine.json';
$folder = $this->createMock(ISimpleFolder::class);
$folder->method('fileExists')
->with('combine.js')
->willReturn(true);
$file = $this->createMock(ISimpleFile::class);
$folder->method('getFile')
->with('combine.js.deps')
Expand All @@ -278,6 +289,9 @@ public function testIsCachedWithNotExistingFile() {
public function testIsCachedWithOlderMtime() {
$fileName = 'combine.json';
$folder = $this->createMock(ISimpleFolder::class);
$folder->method('fileExists')
->with('combine.js')
->willReturn(true);
$file = $this->createMock(ISimpleFile::class);
$folder->method('getFile')
->with('combine.js.deps')
Expand All @@ -293,6 +307,9 @@ public function testIsCachedWithOlderMtime() {
public function testIsCachedWithoutContent() {
$fileName = 'combine.json';
$folder = $this->createMock(ISimpleFolder::class);
$folder->method('fileExists')
->with('combine.js')
->willReturn(true);
$file = $this->createMock(ISimpleFile::class);
$folder->method('getFile')
->with('combine.js.deps')
Expand Down

0 comments on commit 8d86548

Please sign in to comment.