diff options
author | Thomas Müller <thomas.mueller@tmit.eu> | 2015-12-17 16:43:21 +0300 |
---|---|---|
committer | Thomas Müller <thomas.mueller@tmit.eu> | 2015-12-17 16:43:21 +0300 |
commit | e3ed42135dca2d0fce1a46d9e52dd630dadd0e9f (patch) | |
tree | c5b70c9970639dc2b603cf5ca389e30e67fd3409 /core | |
parent | 358b84c21d31fa67dfde75047deb5a66f8c65360 (diff) | |
parent | 3e80f142693fd0d78ff6f4fcd8fd36dd1651e209 (diff) |
Merge pull request #21240 from owncloud/avatar_speedup
Avatar speedup
Diffstat (limited to 'core')
-rw-r--r-- | core/avatar/avatarcontroller.php | 24 |
1 files changed, 14 insertions, 10 deletions
diff --git a/core/avatar/avatarcontroller.php b/core/avatar/avatarcontroller.php index 6c0321e6b5e..e8139aa50ae 100644 --- a/core/avatar/avatarcontroller.php +++ b/core/avatar/avatarcontroller.php @@ -30,6 +30,7 @@ use OCP\AppFramework\Controller; use OCP\AppFramework\Http; use OCP\AppFramework\Http\DataResponse; use OCP\AppFramework\Http\DataDisplayResponse; +use OCP\Files\NotFoundException; use OCP\IAvatarManager; use OCP\ILogger; use OCP\IL10N; @@ -112,20 +113,23 @@ class AvatarController extends Controller { $size = 64; } - $avatar = $this->avatarManager->getAvatar($userId); - $image = $avatar->get($size); - - if ($image instanceof \OCP\IImage) { - $resp = new DataDisplayResponse($image->data(), + try { + $avatar = $this->avatarManager->getAvatar($userId)->getFile($size); + $resp = new DataDisplayResponse($avatar->getContent(), Http::STATUS_OK, - ['Content-Type' => $image->mimeType()]); - $resp->setETag(crc32($image->data())); - } else { + ['Content-Type' => $avatar->getMimeType()]); + $resp->setETag($avatar->getEtag()); + } catch (NotFoundException $e) { $user = $this->userManager->get($userId); - $userName = $user ? $user->getDisplayName() : ''; $resp = new DataResponse([ 'data' => [ - 'displayname' => $userName, + 'displayname' => $user->getDisplayName(), + ], + ]); + } catch (\Exception $e) { + $resp = new DataResponse([ + 'data' => [ + 'displayname' => '', ], ]); } |