Skip to content

Commit 6f21fd1

Browse files
authored
Merge pull request #23504 from nextcloud/backport/23490/stable19
[stable19] Provide log statements for SCSS cache
2 parents 5ce47c8 + 6a1540d commit 6f21fd1

File tree

1 file changed

+25
-10
lines changed

1 file changed

+25
-10
lines changed

lib/private/Template/SCSSCacher.php

Lines changed: 25 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -146,6 +146,7 @@ public function process(string $root, string $file, string $app): bool {
146146
$path = implode('/', $path);
147147
$webDir = $this->getWebDir($path, $app, $this->serverRoot, \OC::$WEBROOT);
148148

149+
$this->logger->debug('SCSSCacher::process ordinary check follows', ['app' => 'scss_cacher']);
149150
if (!$this->variablesChanged() && $this->isCached($fileNameCSS, $app)) {
150151
// Inject icons vars css if any
151152
return $this->injectCssVariablesIfAny();
@@ -161,23 +162,25 @@ public function process(string $root, string $file, string $app): bool {
161162
$lockKey = $webDir . '/' . $fileNameSCSS;
162163

163164
if (!$this->lockingCache->add($lockKey, 'locked!', 120)) {
165+
$this->logger->debug('SCSSCacher::process could not get lock for ' . $lockKey . ' and will wait 10 seconds for cached file to be available', ['app' => 'scss_cacher']);
164166
$retry = 0;
165167
sleep(1);
166168
while ($retry < 10) {
169+
$this->logger->debug('SCSSCacher::process check in while loop follows', ['app' => 'scss_cacher']);
167170
if (!$this->variablesChanged() && $this->isCached($fileNameCSS, $app)) {
168171
// Inject icons vars css if any
169172
$this->lockingCache->remove($lockKey);
170-
$this->logger->debug('SCSSCacher: ' .$lockKey.' is now available after '.$retry.'s. Moving on...', ['app' => 'core']);
173+
$this->logger->debug("SCSSCacher::process cached file for app '$app' and file '$fileNameCSS' is now available after $retry s. Moving on...", ['app' => 'scss_cacher']);
171174
return $this->injectCssVariablesIfAny();
172175
}
173-
$this->logger->debug('SCSSCacher: scss cache file locked for '.$lockKey, ['app' => 'core']);
174176
sleep(1);
175177
$retry++;
176178
}
177-
$this->logger->debug('SCSSCacher: Giving up scss caching for '.$lockKey, ['app' => 'core']);
179+
$this->logger->debug('SCSSCacher::process Giving up scss caching for ' . $lockKey, ['app' => 'scss_cacher']);
178180
return false;
179181
}
180182

183+
$this->logger->debug('SCSSCacher::process Lock acquired for ' . $lockKey, ['app' => 'scss_cacher']);
181184
try {
182185
$cached = $this->cache($path, $fileNameCSS, $fileNameSCSS, $folder, $webDir);
183186
} catch (\Exception $e) {
@@ -187,6 +190,7 @@ public function process(string $root, string $file, string $app): bool {
187190

188191
// Cleaning lock
189192
$this->lockingCache->remove($lockKey);
193+
$this->logger->debug('SCSSCacher::process Lock removed for ' . $lockKey, ['app' => 'scss_cacher']);
190194

191195
// Inject icons vars css if any
192196
if ($this->iconsCacher->getCachedCSS() && $this->iconsCacher->getCachedCSS()->getSize() > 0) {
@@ -224,11 +228,13 @@ private function isCached(string $fileNameCSS, string $app) {
224228
return true;
225229
}
226230
}
231+
$this->logger->debug("SCSSCacher::isCached $fileNameCSS isCachedCache is expired or unset", ['app' => 'scss_cacher']);
227232

228233
// Creating file cache if none for further checks
229234
try {
230235
$folder = $this->appData->getFolder($app);
231236
} catch (NotFoundException $e) {
237+
$this->logger->debug("SCSSCacher::isCached app data folder for $app could not be fetched", ['app' => 'scss_cacher']);
232238
return false;
233239
}
234240

@@ -249,16 +255,20 @@ private function isCached(string $fileNameCSS, string $app) {
249255

250256
foreach ((array) $deps as $file => $mtime) {
251257
if (!file_exists($file) || filemtime($file) > $mtime) {
258+
$this->logger->debug("SCSSCacher::isCached $fileNameCSS is not considered as cached due to deps file $file", ['app' => 'scss_cacher']);
252259
return false;
253260
}
254261
}
255262

263+
$this->logger->debug("SCSSCacher::isCached $fileNameCSS dependencies successfully cached for 5 minutes", ['app' => 'scss_cacher']);
264+
// It would probably make sense to adjust this timeout to something higher and see if that has some effect then
256265
$this->isCachedCache->set($key, $this->timeFactory->getTime() + 5 * 60);
257266
return true;
258267
}
259-
268+
$this->logger->debug("SCSSCacher::isCached $fileNameCSS is not considered as cached cacheValue: $cacheValue", ['app' => 'scss_cacher']);
260269
return false;
261270
} catch (NotFoundException $e) {
271+
$this->logger->debug("SCSSCacher::isCached NotFoundException " . $e->getMessage(), ['app' => 'scss_cacher']);
262272
return false;
263273
}
264274
}
@@ -270,6 +280,7 @@ private function isCached(string $fileNameCSS, string $app) {
270280
private function variablesChanged(): bool {
271281
$injectedVariables = $this->getInjectedVariables();
272282
if ($this->config->getAppValue('core', 'theming.variables') !== md5($injectedVariables)) {
283+
$this->logger->debug('SCSSCacher::variablesChanged storedVariables: ' . json_encode($this->config->getAppValue('core', 'theming.variables')) . ' currentInjectedVariables: ' . json_encode($injectedVariables), ['app' => 'scss_cacher']);
273284
$this->config->setAppValue('core', 'theming.variables', md5($injectedVariables));
274285
$this->resetCache();
275286
return true;
@@ -328,7 +339,7 @@ private function cache(string $path, string $fileNameCSS, string $fileNameSCSS,
328339
'@import "functions.scss";' .
329340
'@import "' . $fileNameSCSS . '";');
330341
} catch (ParserException $e) {
331-
$this->logger->logException($e, ['app' => 'core']);
342+
$this->logger->logException($e, ['app' => 'scss_cacher']);
332343

333344
return false;
334345
}
@@ -350,11 +361,11 @@ private function cache(string $path, string $fileNameCSS, string $fileNameSCSS,
350361
$depFile->putContent($deps);
351362
$this->depsCache->set($folder->getName() . '-' . $depFileName, $deps);
352363
$gzipFile->putContent(gzencode($data, 9));
353-
$this->logger->debug('SCSSCacher: ' . $webDir . '/' . $fileNameSCSS . ' compiled and successfully cached', ['app' => 'core']);
364+
$this->logger->debug('SCSSCacher::cache ' . $webDir . '/' . $fileNameSCSS . ' compiled and successfully cached', ['app' => 'scss_cacher']);
354365

355366
return true;
356367
} catch (NotPermittedException $e) {
357-
$this->logger->error('SCSSCacher: unable to cache: ' . $fileNameSCSS);
368+
$this->logger->error('SCSSCacher::cache unable to cache: ' . $fileNameSCSS, ['app' => 'scss_cacher']);
358369

359370
return false;
360371
}
@@ -365,9 +376,12 @@ private function cache(string $path, string $fileNameCSS, string $fileNameSCSS,
365376
* We need to regenerate all files when variables change
366377
*/
367378
public function resetCache() {
379+
$this->logger->debug('SCSSCacher::resetCache', ['app' => 'scss_cacher']);
368380
if (!$this->lockingCache->add('resetCache', 'locked!', 120)) {
381+
$this->logger->debug('SCSSCacher::resetCache Locked', ['app' => 'scss_cacher']);
369382
return;
370383
}
384+
$this->logger->debug('SCSSCacher::resetCache Lock acquired', ['app' => 'scss_cacher']);
371385
$this->injectedVariables = null;
372386

373387
// do not clear locks
@@ -380,12 +394,13 @@ public function resetCache() {
380394
try {
381395
$file->delete();
382396
} catch (NotPermittedException $e) {
383-
$this->logger->logException($e, ['message' => 'SCSSCacher: unable to delete file: ' . $file->getName()]);
397+
$this->logger->logException($e, ['message' => 'SCSSCacher::resetCache unable to delete file: ' . $file->getName(), 'app' => 'scss_cacher']);
384398
}
385399
}
386400
}
387-
$this->logger->debug('SCSSCacher: css cache cleared!');
401+
$this->logger->debug('SCSSCacher::resetCache css cache cleared!', ['app' => 'scss_cacher']);
388402
$this->lockingCache->remove('resetCache');
403+
$this->logger->debug('SCSSCacher::resetCache Locking removed', ['app' => 'scss_cacher']);
389404
}
390405

391406
/**
@@ -406,7 +421,7 @@ private function getInjectedVariables(): string {
406421
$scss->compile($variables);
407422
$this->injectedVariables = $variables;
408423
} catch (ParserException $e) {
409-
$this->logger->logException($e, ['app' => 'core']);
424+
$this->logger->logException($e, ['app' => 'scss_cacher']);
410425
}
411426

412427
return $variables;

0 commit comments

Comments
 (0)