Skip to content

Commit 473089f

Browse files
Merge pull request #62053 from nextcloud/backport/61957/stable33
[stable33] perf(carddav): reduce disk usage of photocache
2 parents 885ddfe + 40780cc commit 473089f

1 file changed

Lines changed: 10 additions & 3 deletions

File tree

apps/dav/lib/CardDAV/PhotoCache.php

Lines changed: 10 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,9 @@
2424
class PhotoCache {
2525
private ?IAppData $photoCacheAppData = null;
2626

27+
/** Maximum edge length (in pixels) for photos */
28+
private const MAX_SIZE = 2048;
29+
2730
/** @var array */
2831
public const ALLOWED_CONTENT_TYPES = [
2932
'image/png' => 'png',
@@ -98,6 +101,9 @@ private function hasPhoto(ISimpleFolder $folder): bool {
98101
private function getFile(ISimpleFolder $folder, $size): ISimpleFile {
99102
$ext = $this->getExtension($folder);
100103

104+
// cap the size
105+
$size = (int)min($size, self::MAX_SIZE);
106+
101107
if ($size === -1) {
102108
$path = 'photo.' . $ext;
103109
} else {
@@ -122,9 +128,10 @@ private function getFile(ISimpleFolder $folder, $size): ISimpleFile {
122128
}
123129

124130
$size = (int)($size * $ratio);
125-
if ($size !== -1) {
126-
$photo->resize($size);
127-
}
131+
// cap the size
132+
$size = min($size, self::MAX_SIZE);
133+
134+
$photo->resize($size);
128135

129136
try {
130137
$file = $folder->newFile($path);

0 commit comments

Comments
 (0)