Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: Log large assets that are initially loaded on the frontend #43429

Closed
wants to merge 1 commit into from
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
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) {
szaimen marked this conversation as resolved.
Show resolved Hide resolved
$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
Loading