Преглед на файлове

Merge pull request #23934 from nextcloud/enh/avoid_scss_compile

tags/v21.0.0beta1
John Molakvoæ преди 3 години
родител
ревизия
d25e5366b8
No account linked to committer's email address
променени са 2 файла, в които са добавени 18 реда и са изтрити 3 реда
  1. 13
    3
      lib/private/Template/SCSSCacher.php
  2. 5
    0
      tests/lib/Template/SCSSCacherTest.php

+ 13
- 3
lib/private/Template/SCSSCacher.php Целия файл

* @return bool * @return bool
*/ */
private function variablesChanged(): bool { private function variablesChanged(): bool {
$injectedVariables = $this->getInjectedVariables();
if ($this->config->getAppValue('core', 'theming.variables') !== md5($injectedVariables)) {
$cachedVariables = $this->config->getAppValue('core', 'theming.variables', '');
$injectedVariables = $this->getInjectedVariables($cachedVariables);
if ($cachedVariables !== md5($injectedVariables)) {
$this->logger->debug('SCSSCacher::variablesChanged storedVariables: ' . json_encode($this->config->getAppValue('core', 'theming.variables')) . ' currentInjectedVariables: ' . json_encode($injectedVariables), ['app' => 'scss_cacher']); $this->logger->debug('SCSSCacher::variablesChanged storedVariables: ' . json_encode($this->config->getAppValue('core', 'theming.variables')) . ' currentInjectedVariables: ' . json_encode($injectedVariables), ['app' => 'scss_cacher']);
$this->config->setAppValue('core', 'theming.variables', md5($injectedVariables)); $this->config->setAppValue('core', 'theming.variables', md5($injectedVariables));
$this->resetCache(); $this->resetCache();
/** /**
* @return string SCSS code for variables from OC_Defaults * @return string SCSS code for variables from OC_Defaults
*/ */
private function getInjectedVariables(): string {
private function getInjectedVariables(string $cache = ''): string {
if ($this->injectedVariables !== null) { if ($this->injectedVariables !== null) {
return $this->injectedVariables; return $this->injectedVariables;
} }
$variables .= '$' . $key . ': ' . $value . ' !default;'; $variables .= '$' . $key . ': ' . $value . ' !default;';
} }


/*
* If we are trying to return the same variables as that are cached
* Then there is no need to do the compile step
*/
if ($cache === md5($variables)) {
$this->injectedVariables = $variables;
return $variables;
}

// check for valid variables / otherwise fall back to defaults // check for valid variables / otherwise fall back to defaults
try { try {
$scss = new Compiler(); $scss = new Compiler();

+ 5
- 0
tests/lib/Template/SCSSCacherTest.php Целия файл

->willReturn('http://localhost/nextcloud'); ->willReturn('http://localhost/nextcloud');


$this->config = $this->createMock(IConfig::class); $this->config = $this->createMock(IConfig::class);
$this->config->expects($this->any())
->method('getAppValue')
->will($this->returnCallback(function ($appId, $configKey, $defaultValue) {
return $defaultValue;
}));
$this->cacheFactory = $this->createMock(ICacheFactory::class); $this->cacheFactory = $this->createMock(ICacheFactory::class);
$this->depsCache = $this->createMock(ICache::class); $this->depsCache = $this->createMock(ICache::class);
$this->cacheFactory->expects($this->at(0)) $this->cacheFactory->expects($this->at(0))

Loading…
Отказ
Запис