Skip to content

Commit 638d82e

Browse files
committed
Clear cached app config while waiting for the SCSSCache to finish processing the file
Signed-off-by: Morris Jobke <hey@morrisjobke.de>
1 parent 79a9fef commit 638d82e

File tree

4 files changed

+30
-3
lines changed

4 files changed

+30
-3
lines changed

lib/private/AppConfig.php

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -343,4 +343,14 @@ protected function loadConfigValues() {
343343

344344
$this->configLoaded = true;
345345
}
346+
347+
/**
348+
* Clear all the cached app config values
349+
*
350+
* WARNING: do not use this - this is only for usage with the SCSSCacher to
351+
* clear the memory cache of the app config
352+
*/
353+
public function clearCachedConfig() {
354+
$this->configLoaded = false;
355+
}
346356
}

lib/private/Template/SCSSCacher.php

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -30,6 +30,7 @@
3030

3131
namespace OC\Template;
3232

33+
use OC\AppConfig;
3334
use OC\Files\AppData\Factory;
3435
use OC\Memcache\NullCache;
3536
use OCP\AppFramework\Utility\ITimeFactory;
@@ -89,6 +90,8 @@ class SCSSCacher {
8990

9091
/** @var IMemcache */
9192
private $lockingCache;
93+
/** @var AppConfig */
94+
private $appConfig;
9295

9396
/**
9497
* @param ILogger $logger
@@ -109,7 +112,8 @@ public function __construct(ILogger $logger,
109112
$serverRoot,
110113
ICacheFactory $cacheFactory,
111114
IconsCacher $iconsCacher,
112-
ITimeFactory $timeFactory) {
115+
ITimeFactory $timeFactory,
116+
AppConfig $appConfig) {
113117
$this->logger = $logger;
114118
$this->appData = $appDataFactory->get('css');
115119
$this->urlGenerator = $urlGenerator;
@@ -126,6 +130,7 @@ public function __construct(ILogger $logger,
126130
$this->lockingCache = $lockingCache;
127131
$this->iconsCacher = $iconsCacher;
128132
$this->timeFactory = $timeFactory;
133+
$this->appConfig = $appConfig;
129134
}
130135

131136
/**
@@ -166,6 +171,7 @@ public function process(string $root, string $file, string $app): bool {
166171
$retry = 0;
167172
sleep(1);
168173
while ($retry < 10) {
174+
$this->appConfig->clearCachedConfig();
169175
$this->logger->debug('SCSSCacher::process check in while loop follows', ['app' => 'scss_cacher']);
170176
if (!$this->variablesChanged() && $this->isCached($fileNameCSS, $app)) {
171177
// Inject icons vars css if any

tests/lib/Template/CSSResourceLocatorTest.php

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,7 @@
2323

2424
namespace Test\Template;
2525

26+
use OC\AppConfig;
2627
use OC\Files\AppData\AppData;
2728
use OC\Files\AppData\Factory;
2829
use OC\Template\CSSResourceLocator;
@@ -53,6 +54,8 @@ class CSSResourceLocatorTest extends \Test\TestCase {
5354
protected $iconsCacher;
5455
/** @var ITimeFactory|\PHPUnit_Framework_MockObject_MockObject */
5556
private $timeFactory;
57+
/** @var AppConfig|\PHPUnit\Framework\MockObject\MockObject */
58+
private $appConfig;
5659

5760
protected function setUp(): void {
5861
parent::setUp();
@@ -65,6 +68,7 @@ protected function setUp(): void {
6568
$this->themingDefaults = $this->createMock(ThemingDefaults::class);
6669
$this->iconsCacher = $this->createMock(IconsCacher::class);
6770
$this->timeFactory = $this->createMock(ITimeFactory::class);
71+
$this->appConfig = $this->createMock(AppConfig::class);
6872
}
6973

7074
private function cssResourceLocator() {
@@ -80,7 +84,8 @@ private function cssResourceLocator() {
8084
\OC::$SERVERROOT,
8185
$this->cacheFactory,
8286
$this->iconsCacher,
83-
$this->timeFactory
87+
$this->timeFactory,
88+
$this->appConfig
8489
);
8590
return new CSSResourceLocator(
8691
$this->logger,

tests/lib/Template/SCSSCacherTest.php

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,7 @@
2323

2424
namespace Test\Template;
2525

26+
use OC\AppConfig;
2627
use OC\Files\AppData\AppData;
2728
use OC\Files\AppData\Factory;
2829
use OC\Template\IconsCacher;
@@ -60,6 +61,8 @@ class SCSSCacherTest extends \Test\TestCase {
6061
protected $iconsCacher;
6162
/** @var ITimeFactory|\PHPUnit_Framework_MockObject_MockObject */
6263
protected $timeFactory;
64+
/** @var AppConfig|\PHPUnit\Framework\MockObject\MockObject */
65+
protected $appConfig;
6366

6467
protected function setUp(): void {
6568
parent::setUp();
@@ -92,6 +95,8 @@ protected function setUp(): void {
9295
->method('getCachedCSS')
9396
->willReturn($iconsFile);
9497

98+
$this->appConfig = $this->createMock(AppConfig::class);
99+
95100
$this->scssCacher = new SCSSCacher(
96101
$this->logger,
97102
$factory,
@@ -101,7 +106,8 @@ protected function setUp(): void {
101106
\OC::$SERVERROOT,
102107
$this->cacheFactory,
103108
$this->iconsCacher,
104-
$this->timeFactory
109+
$this->timeFactory,
110+
$this->appConfig
105111
);
106112
}
107113

0 commit comments

Comments
 (0)