Skip to content

Commit

Permalink
Clear cached app config while waiting for the SCSSCache to finish pro…
Browse files Browse the repository at this point in the history
…cessing the file

Signed-off-by: Morris Jobke <[email protected]>
  • Loading branch information
MorrisJobke committed Oct 16, 2020
1 parent 79a9fef commit c48076c
Show file tree
Hide file tree
Showing 5 changed files with 32 additions and 4 deletions.
10 changes: 10 additions & 0 deletions lib/private/AppConfig.php
Original file line number Diff line number Diff line change
Expand Up @@ -343,4 +343,14 @@ protected function loadConfigValues() {

$this->configLoaded = true;
}

/**
* Clear all the cached app config values
*
* WARNING: do not use this - this is only for usage with the SCSSCacher to
* clear the memory cache of the app config
*/
public function clearCachedConfig() {
$this->configLoaded = false;
}
}
3 changes: 2 additions & 1 deletion lib/private/Server.php
Original file line number Diff line number Diff line change
Expand Up @@ -1143,7 +1143,8 @@ public function __construct($webRoot, \OC\Config $config) {
\OC::$SERVERROOT,
$this->getMemCacheFactory(),
$c->query(IconsCacher::class),
new TimeFactory()
new TimeFactory(),
$c->query(AppConfig::class)
);
});
$this->registerService(JSCombiner::class, function (Server $c) {
Expand Down
8 changes: 7 additions & 1 deletion lib/private/Template/SCSSCacher.php
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,7 @@

namespace OC\Template;

use OC\AppConfig;
use OC\Files\AppData\Factory;
use OC\Memcache\NullCache;
use OCP\AppFramework\Utility\ITimeFactory;
Expand Down Expand Up @@ -89,6 +90,8 @@ class SCSSCacher {

/** @var IMemcache */
private $lockingCache;
/** @var AppConfig */
private $appConfig;

/**
* @param ILogger $logger
Expand All @@ -109,7 +112,8 @@ public function __construct(ILogger $logger,
$serverRoot,
ICacheFactory $cacheFactory,
IconsCacher $iconsCacher,
ITimeFactory $timeFactory) {
ITimeFactory $timeFactory,
AppConfig $appConfig) {
$this->logger = $logger;
$this->appData = $appDataFactory->get('css');
$this->urlGenerator = $urlGenerator;
Expand All @@ -126,6 +130,7 @@ public function __construct(ILogger $logger,
$this->lockingCache = $lockingCache;
$this->iconsCacher = $iconsCacher;
$this->timeFactory = $timeFactory;
$this->appConfig = $appConfig;
}

/**
Expand Down Expand Up @@ -166,6 +171,7 @@ public function process(string $root, string $file, string $app): bool {
$retry = 0;
sleep(1);
while ($retry < 10) {
$this->appConfig->clearCachedConfig();
$this->logger->debug('SCSSCacher::process check in while loop follows', ['app' => 'scss_cacher']);
if (!$this->variablesChanged() && $this->isCached($fileNameCSS, $app)) {
// Inject icons vars css if any
Expand Down
7 changes: 6 additions & 1 deletion tests/lib/Template/CSSResourceLocatorTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@

namespace Test\Template;

use OC\AppConfig;
use OC\Files\AppData\AppData;
use OC\Files\AppData\Factory;
use OC\Template\CSSResourceLocator;
Expand Down Expand Up @@ -53,6 +54,8 @@ class CSSResourceLocatorTest extends \Test\TestCase {
protected $iconsCacher;
/** @var ITimeFactory|\PHPUnit_Framework_MockObject_MockObject */
private $timeFactory;
/** @var AppConfig|\PHPUnit\Framework\MockObject\MockObject */
private $appConfig;

protected function setUp(): void {
parent::setUp();
Expand All @@ -65,6 +68,7 @@ protected function setUp(): void {
$this->themingDefaults = $this->createMock(ThemingDefaults::class);
$this->iconsCacher = $this->createMock(IconsCacher::class);
$this->timeFactory = $this->createMock(ITimeFactory::class);
$this->appConfig = $this->createMock(AppConfig::class);
}

private function cssResourceLocator() {
Expand All @@ -80,7 +84,8 @@ private function cssResourceLocator() {
\OC::$SERVERROOT,
$this->cacheFactory,
$this->iconsCacher,
$this->timeFactory
$this->timeFactory,
$this->appConfig
);
return new CSSResourceLocator(
$this->logger,
Expand Down
8 changes: 7 additions & 1 deletion tests/lib/Template/SCSSCacherTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@

namespace Test\Template;

use OC\AppConfig;
use OC\Files\AppData\AppData;
use OC\Files\AppData\Factory;
use OC\Template\IconsCacher;
Expand Down Expand Up @@ -60,6 +61,8 @@ class SCSSCacherTest extends \Test\TestCase {
protected $iconsCacher;
/** @var ITimeFactory|\PHPUnit_Framework_MockObject_MockObject */
protected $timeFactory;
/** @var AppConfig|\PHPUnit\Framework\MockObject\MockObject */
protected $appConfig;

protected function setUp(): void {
parent::setUp();
Expand Down Expand Up @@ -92,6 +95,8 @@ protected function setUp(): void {
->method('getCachedCSS')
->willReturn($iconsFile);

$this->appConfig = $this->createMock(AppConfig::class);

$this->scssCacher = new SCSSCacher(
$this->logger,
$factory,
Expand All @@ -101,7 +106,8 @@ protected function setUp(): void {
\OC::$SERVERROOT,
$this->cacheFactory,
$this->iconsCacher,
$this->timeFactory
$this->timeFactory,
$this->appConfig
);
}

Expand Down

0 comments on commit c48076c

Please sign in to comment.