Skip to content

Commit

Permalink
feat: Log large assets that are initially loaded on the frontend
Browse files Browse the repository at this point in the history
Signed-off-by: Julius Härtl <jus@bitgrid.net>
  • Loading branch information
juliusknorr committed Feb 8, 2024
1 parent 9e90401 commit 94f77fb
Show file tree
Hide file tree
Showing 3 changed files with 18 additions and 2 deletions.
4 changes: 4 additions & 0 deletions lib/private/Share20/DefaultShareProvider.php
Original file line number Diff line number Diff line change
Expand Up @@ -943,6 +943,10 @@ public function getSharedWith($userId, $shareType, $node, $limit, $offset) {
$user = $this->userManager->get($userId);
$allGroups = ($user instanceof IUser) ? $this->groupManager->getUserGroupIds($user) : [];

if ($allGroups === []) {
return [];
}

/** @var Share[] $shares2 */
$shares2 = [];

Expand Down
7 changes: 7 additions & 0 deletions lib/private/Template/ResourceLocator.php
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,7 @@
*/
namespace OC\Template;

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

abstract class ResourceLocator {
Expand All @@ -42,6 +43,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 @@ -98,6 +101,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 @@ -30,8 +30,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

0 comments on commit 94f77fb

Please sign in to comment.