Skip to content

Commit

Permalink
Avoid file system access on checking if an image exists
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 Jan 5, 2022
1 parent f9b06de commit 90376e2
Showing 1 changed file with 6 additions and 3 deletions.
9 changes: 6 additions & 3 deletions apps/theming/lib/ImageManager.php
Original file line number Diff line number Diff line change
Expand Up @@ -78,10 +78,8 @@ public function __construct(IConfig $config,

public function getImageUrl(string $key, bool $useSvg = true): string {
$cacheBusterCounter = $this->config->getAppValue('theming', 'cachebuster', '0');
try {
$image = $this->getImage($key, $useSvg);
if ($this->hasImage($key)) {
return $this->urlGenerator->linkToRoute('theming.Theming.getImage', [ 'key' => $key ]) . '?v=' . $cacheBusterCounter;
} catch (NotFoundException $e) {
}

switch ($key) {
Expand Down Expand Up @@ -131,6 +129,11 @@ public function getImage(string $key, bool $useSvg = true): ISimpleFile {
return $folder->getFile($key);
}

public function hasImage(string $key): bool {
$mimeSetting = $this->config->getAppValue('theming', $key . 'Mime', '');
return $mimeSetting !== '';
}

public function getCustomImages(): array {
$images = [];
foreach ($this->supportedImageKeys as $key) {
Expand Down

0 comments on commit 90376e2

Please sign in to comment.