Skip to content
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
feat: Log large assets that are initially loaded on the frontend
Signed-off-by: Julius Härtl <[email protected]>
  • Loading branch information
juliusknorr committed Jun 25, 2024
commit ecfbcc66d5322ac0020732690117ac8c3dad45ac
7 changes: 7 additions & 0 deletions lib/private/Template/ResourceLocator.php
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@
*/
namespace OC\Template;

use OC\SystemConfig;
use Psr\Log\LoggerInterface;

abstract class ResourceLocator {
Expand All @@ -20,6 +21,8 @@ abstract class ResourceLocator {

protected LoggerInterface $logger;

private const LOG_LARGE_ASSET_OFFSET = 1024 * 1024;

public function __construct(LoggerInterface $logger) {
$this->logger = $logger;
$this->mapping = [
Expand Down Expand Up @@ -76,6 +79,10 @@ public function find($resources) {
*/
protected function appendIfExist($root, $file, $webRoot = null) {
if ($root !== false && is_file($root.'/'.$file)) {
$systemConfig = \OCP\Server::get(SystemConfig::class);
if ($systemConfig->getValue('debug', false) && filesize($root.'/'.$file) > self::LOG_LARGE_ASSET_OFFSET) {
$this->logger->debug("$root/$file is larger then 1MB, consider reducing the size for javascript entrypoints");
}
$this->append($root, $file, $webRoot, false);
return true;
}
Expand Down
9 changes: 7 additions & 2 deletions tests/lib/Template/ResourceLocatorTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -29,8 +29,13 @@ public function getResourceLocator($theme) {
$systemConfig
->expects($this->any())
->method('getValue')
->with('theme', '')
->willReturn($theme);
->willReturnCallback(function ($key, $default = null) use ($theme) {
if ($key === 'theme') {
return $theme;
}

return $default;
});
$this->overwriteService(SystemConfig::class, $systemConfig);
return $this->getMockForAbstractClass('OC\Template\ResourceLocator',
[$this->logger],
Expand Down