Browse Source

Minor refactoring

Signed-off-by: Dariusz Olszewski <starypatyk@users.noreply.github.com>
pull/7743/head
Dariusz Olszewski 3 years ago
parent
commit
4c4f43a761
  1. 44
      lib/Controller/ChatController.php
  2. 2
      lib/Share/RoomShareProvider.php

44
lib/Controller/ChatController.php

@ -309,6 +309,31 @@ class ChatController extends AEnvironmentAwareController {
return $this->parseCommentToResponse($comment);
}
/*
* Gather share IDs from the comments and preload share definitions
* to avoid separate database query for each individual share.
*/
protected function preloadShares(array $comments) {
// Scan messages for share IDs
$shareIds = [];
foreach ($comments as $comment) {
$verb = $comment->getVerb();
if ($verb === 'object_shared') {
$message = $comment->getMessage();
$data = json_decode($message, true);
if (isset($data['parameters']['share'])) {
$shareIds[] = $data['parameters']['share'];
}
}
}
if (!empty($shareIds)) {
// Ignore the result for now. Retrieved Share objects will be cached by
// the RoomShareProvider and returned from the cache to
// the Parser\SystemMessage without additional database queries.
$this->shareProvider->getSharesByIds($shareIds);
}
}
/**
* @PublicPage
* @RequireParticipant
@ -436,24 +461,7 @@ class ChatController extends AEnvironmentAwareController {
return $response;
}
// Quickly scan messages for share IDs
$shareIds = [];
foreach ($comments as $comment) {
$verb = $comment->getVerb();
if ($verb === 'object_shared') {
$message = $comment->getMessage();
$data = json_decode($message, true);
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.
if (!empty($shareIds)) {
$this->shareProvider->getSharesByIds($shareIds);
}
$this->preloadShares($comments);
$i = 0;
$messages = $commentIdToIndex = $parentIds = [];

2
lib/Share/RoomShareProvider.php

@ -28,7 +28,6 @@ declare(strict_types=1);
namespace OCA\Talk\Share;
use OCP\Cache\CappedMemoryCache;
use OC\Files\Cache\Cache;
use OCA\Talk\Events\AlreadySharedEvent;
use OCA\Talk\Events\RoomEvent;
@ -39,6 +38,7 @@ use OCA\Talk\Model\Attendee;
use OCA\Talk\Room;
use OCA\Talk\Service\ParticipantService;
use OCP\AppFramework\Utility\ITimeFactory;
use OCP\Cache\CappedMemoryCache;
use OCP\DB\QueryBuilder\IQueryBuilder;
use OCP\EventDispatcher\IEventDispatcher;
use OCP\Files\Folder;

Loading…
Cancel
Save