From: Roeland Jago Douma Date: Tue, 21 Mar 2017 20:53:20 +0000 (+0100) Subject: Cache SCSS dependency file in memcache X-Git-Tag: v12.0.0beta1~332^2~1 X-Git-Url: https://source.dussan.org/?a=commitdiff_plain;h=e3925ba2a1de18692f2687569c1f490a24ec11d3;p=nextcloud-server.git Cache SCSS dependency file in memcache Since reading a file from disks can be costly. Lets store the dependency json also in memcache. Signed-off-by: Roeland Jago Douma --- diff --git a/lib/private/Template/SCSSCacher.php b/lib/private/Template/SCSSCacher.php index 4f5c66f2409..c12d8771513 100644 --- a/lib/private/Template/SCSSCacher.php +++ b/lib/private/Template/SCSSCacher.php @@ -30,6 +30,7 @@ use OCP\Files\IAppData; use OCP\Files\NotFoundException; use OCP\Files\NotPermittedException; use OCP\Files\SimpleFS\ISimpleFolder; +use OCP\ICache; use OCP\IConfig; use OCP\ILogger; use OCP\IURLGenerator; @@ -51,23 +52,29 @@ class SCSSCacher { /** @var string */ protected $serverRoot; + /** @var ICache */ + protected $depsCache; + /** * @param ILogger $logger * @param IAppData $appData * @param IURLGenerator $urlGenerator - * @param SystemConfig $systemConfig + * @param IConfig $config * @param string $serverRoot + * @param ICache $depsCache */ public function __construct(ILogger $logger, IAppData $appData, IURLGenerator $urlGenerator, IConfig $config, - $serverRoot) { + $serverRoot, + ICache $depsCache) { $this->logger = $logger; $this->appData = $appData; $this->urlGenerator = $urlGenerator; $this->config = $config; $this->serverRoot = $serverRoot; + $this->depsCache = $depsCache; } /** @@ -94,7 +101,7 @@ class SCSSCacher { $folder = $this->appData->newFolder($app); } - if($this->isCached($fileNameCSS, $fileNameSCSS, $folder, $path)) { + if($this->isCached($fileNameCSS, $folder)) { return true; } return $this->cache($path, $fileNameCSS, $fileNameSCSS, $folder, $webDir); @@ -103,17 +110,22 @@ class SCSSCacher { /** * Check if the file is cached or not * @param string $fileNameCSS - * @param string $fileNameSCSS * @param ISimpleFolder $folder - * @param string $path * @return boolean */ - private function isCached($fileNameCSS, $fileNameSCSS, ISimpleFolder $folder, $path) { + private function isCached($fileNameCSS, ISimpleFolder $folder) { try { $cachedFile = $folder->getFile($fileNameCSS); if ($cachedFile->getSize() > 0) { - $depFile = $folder->getFile($fileNameCSS . '.deps'); - $deps = json_decode($depFile->getContent(), true); + $depFileName = $fileNameCSS . '.deps'; + $deps = $this->depsCache->get($folder->getName() . '-' . $depFileName); + if ($deps === null) { + $depFile = $folder->getFile($depFileName); + $deps = $depFile->getContent(); + //Set to memcache for next run + $this->depsCache->set($folder->getName() . '-' . $depFileName, $deps); + } + $deps = json_decode($deps, true); foreach ($deps as $file=>$mtime) { if (!file_exists($file) || filemtime($file) > $mtime) { diff --git a/lib/private/TemplateLayout.php b/lib/private/TemplateLayout.php index 33f61e3c3ac..3206a1d3ba8 100644 --- a/lib/private/TemplateLayout.php +++ b/lib/private/TemplateLayout.php @@ -213,12 +213,15 @@ class TemplateLayout extends \OC_Template { $theme = \OC_Util::getTheme(); if($compileScss) { + /** @var \OC\Memcache\Factory $cache */ + $cache = \OC::$server->query('MemCacheFactory'); $SCSSCacher = new SCSSCacher( \OC::$server->getLogger(), \OC::$server->getAppDataDir('css'), \OC::$server->getURLGenerator(), \OC::$server->getConfig(), - \OC::$SERVERROOT + \OC::$SERVERROOT, + $cache->createLocal('SCSS') ); } else { $SCSSCacher = null; diff --git a/tests/lib/Template/SCSSCacherTest.php b/tests/lib/Template/SCSSCacherTest.php index d49f0cdc6a1..b345c673871 100644 --- a/tests/lib/Template/SCSSCacherTest.php +++ b/tests/lib/Template/SCSSCacherTest.php @@ -28,6 +28,7 @@ use OCP\Files\IAppData; use OCP\Files\NotFoundException; use OCP\Files\SimpleFS\ISimpleFile; use OCP\Files\SimpleFS\ISimpleFolder; +use OCP\ICache; use OCP\IConfig; use OCP\ILogger; use OCP\IURLGenerator; @@ -57,7 +58,8 @@ class SCSSCacherTest extends \Test\TestCase { $this->appData, $this->urlGenerator, $this->config, - \OC::$SERVERROOT + \OC::$SERVERROOT, + $this->createMock(ICache::class) ); } @@ -275,4 +277,4 @@ class SCSSCacherTest extends \Test\TestCase { } -} \ No newline at end of file +}