Skip to content

Commit 60454ab

Browse files
committed
Clear cached app config while waiting for the SCSSCache to finish processing the file
Signed-off-by: Morris Jobke <[email protected]>
1 parent 20043ac commit 60454ab

File tree

4 files changed

+29
-3
lines changed

4 files changed

+29
-3
lines changed

lib/private/AppConfig.php

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

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

lib/private/Template/SCSSCacher.php

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -89,6 +89,8 @@ class SCSSCacher {
8989

9090
/** @var IMemcache */
9191
private $lockingCache;
92+
/** @var AppConfig */
93+
private $appConfig;
9294

9395
/**
9496
* @param ILogger $logger
@@ -109,7 +111,8 @@ public function __construct(ILogger $logger,
109111
$serverRoot,
110112
ICacheFactory $cacheFactory,
111113
IconsCacher $iconsCacher,
112-
ITimeFactory $timeFactory) {
114+
ITimeFactory $timeFactory,
115+
AppConfig $appConfig) {
113116
$this->logger = $logger;
114117
$this->appData = $appDataFactory->get('css');
115118
$this->urlGenerator = $urlGenerator;
@@ -126,6 +129,7 @@ public function __construct(ILogger $logger,
126129
$this->lockingCache = $lockingCache;
127130
$this->iconsCacher = $iconsCacher;
128131
$this->timeFactory = $timeFactory;
132+
$this->appConfig = $appConfig;
129133
}
130134

131135
/**
@@ -166,6 +170,7 @@ public function process(string $root, string $file, string $app): bool {
166170
$retry = 0;
167171
sleep(1);
168172
while ($retry < 10) {
173+
$this->appConfig->clearCachedConfig();
169174
$this->logger->debug('SCSSCacher::process check in while loop follows', ['app' => 'scss_cacher']);
170175
if (!$this->variablesChanged() && $this->isCached($fileNameCSS, $app)) {
171176
// 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;
@@ -61,6 +62,8 @@ class SCSSCacherTest extends \Test\TestCase {
6162
protected $iconsCacher;
6263
/** @var ITimeFactory|\PHPUnit_Framework_MockObject_MockObject */
6364
protected $timeFactory;
65+
/** @var AppConfig|\PHPUnit\Framework\MockObject\MockObject */
66+
protected $appConfig;
6467

6568
protected function setUp(): void {
6669
parent::setUp();
@@ -93,6 +96,8 @@ protected function setUp(): void {
9396
->method('getCachedCSS')
9497
->willReturn($iconsFile);
9598

99+
$this->appConfig = $this->createMock(AppConfig::class);
100+
96101
$this->scssCacher = new SCSSCacher(
97102
$this->logger,
98103
$factory,
@@ -102,7 +107,8 @@ protected function setUp(): void {
102107
\OC::$SERVERROOT,
103108
$this->cacheFactory,
104109
$this->iconsCacher,
105-
$this->timeFactory
110+
$this->timeFactory,
111+
$this->appConfig
106112
);
107113
}
108114

0 commit comments

Comments
 (0)