From 3e17b5c95d7c4c572d8e383f3579a7a0c82ea79f Mon Sep 17 00:00:00 2001 From: Dariusz Olszewski <8277636+starypatyk@users.noreply.github.com> Date: Wed, 17 Aug 2022 20:57:57 +0200 Subject: Apply suggestions from code review Co-authored-by: Joas Schilling <213943+nickvergessen@users.noreply.github.com> Signed-off-by: Dariusz Olszewski <8277636+starypatyk@users.noreply.github.com> --- lib/Controller/ChatController.php | 13 ++++++++----- lib/Share/RoomShareProvider.php | 6 +++--- 2 files changed, 11 insertions(+), 8 deletions(-) diff --git a/lib/Controller/ChatController.php b/lib/Controller/ChatController.php index 1635e6852..a9fca6455 100644 --- a/lib/Controller/ChatController.php +++ b/lib/Controller/ChatController.php @@ -437,20 +437,23 @@ class ChatController extends AEnvironmentAwareController { } // Quickly scan messages for share IDs - $share_ids = []; + $shareIds = []; foreach ($comments as $comment) { $verb = $comment->getVerb(); - $message = $comment->getMessage(); if ($verb === 'object_shared') { + $message = $comment->getMessage(); $data = json_decode($message, true); - $parameters = $data['parameters']; - $share_ids[] = $parameters['share']; + if (isset($data['parameters']['share'])) { + $shareIds[] = $data['parameters']['share']; + } } } // Ignore the result for now. Retrieved Share objects will be cached by // the RoomShareProvider and returned from the cache to // the MessageParser without additional database queries. - $this->shareProvider->getSharesByIds($share_ids); + if (!empty($shareIds)) { + $this->shareProvider->getSharesByIds($shareIds); + } $i = 0; $messages = $commentIdToIndex = $parentIds = []; diff --git a/lib/Share/RoomShareProvider.php b/lib/Share/RoomShareProvider.php index 229a23267..653083d96 100644 --- a/lib/Share/RoomShareProvider.php +++ b/lib/Share/RoomShareProvider.php @@ -28,7 +28,7 @@ declare(strict_types=1); namespace OCA\Talk\Share; -use OC\Cache\CappedMemoryCache; +use OCP\Cache\CappedMemoryCache; use OC\Files\Cache\Cache; use OCA\Talk\Events\AlreadySharedEvent; use OCA\Talk\Events\RoomEvent; @@ -84,7 +84,7 @@ class RoomShareProvider implements IShareProvider { private IL10N $l; private IMimeTypeLoader $mimeTypeLoader; - private $sharesByIdCache; + private CappedMemoryCache $sharesByIdCache; public function __construct( IDBConnection $connection, @@ -684,7 +684,7 @@ class RoomShareProvider implements IShareProvider { * @return IShare[] * @throws ShareNotFound */ - public function getSharesByIds($ids, $recipientId = null): array { + public function getSharesByIds(array $ids, ?string $recipientId = null): array { $qb = $this->dbConnection->getQueryBuilder(); $qb->select('s.*', -- cgit v1.2.3