Skip to content

Commit

Permalink
Use displayname cache for fetching session data
Browse files Browse the repository at this point in the history
Signed-off-by: Julius Härtl <jus@bitgrid.net>
  • Loading branch information
juliushaertl committed Aug 17, 2022
1 parent 48b21b6 commit d0d8562
Showing 1 changed file with 10 additions and 21 deletions.
31 changes: 10 additions & 21 deletions lib/Service/SessionService.php
Original file line number Diff line number Diff line change
Expand Up @@ -32,22 +32,17 @@
use OCP\ICache;
use OCP\ICacheFactory;
use OCP\IRequest;
use OCP\IUserManager;
use OCP\Security\ISecureRandom;

class SessionService {
public const SESSION_VALID_TIME = 5 * 60;

/** @var SessionMapper */
private $sessionMapper;

/** @var ISecureRandom */
private $secureRandom;

/** @var ITimeFactory */
private $timeFactory;

/** @var IAvatarManager */
private $avatarManager;
private SessionMapper $sessionMapper;
private ISecureRandom $secureRandom;
private ITimeFactory $timeFactory;
private IUserManager $userManager;
private IAvatarManager $avatarManager;

/** @var string|null */
private $userId;
Expand All @@ -62,6 +57,7 @@ public function __construct(
SessionMapper $sessionMapper,
ISecureRandom $secureRandom,
ITimeFactory $timeFactory,
IUserManager $userManager,
IAvatarManager $avatarManager,
IRequest $request,
IManager $directManager,
Expand All @@ -71,6 +67,7 @@ public function __construct(
$this->sessionMapper = $sessionMapper;
$this->secureRandom = $secureRandom;
$this->timeFactory = $timeFactory;
$this->userManager = $userManager;
$this->avatarManager = $avatarManager;
$this->userId = $userId;

Expand Down Expand Up @@ -119,11 +116,7 @@ public function getAllSessions($documentId): array {
$sessions = $this->sessionMapper->findAll($documentId);
return array_map(function (Session $session) {
$result = $session->jsonSerialize();
$userManager = \OC::$server->getUserManager();
$user = $userManager->get($session->getUserId());
if ($user) {
$result['displayName'] = $user->getDisplayName();
}
$result['displayName'] = $this->userManager->getDisplayName($session->getUserId());
return $result;
}, $sessions);
}
Expand All @@ -132,11 +125,7 @@ public function getActiveSessions($documentId): array {
$sessions = $this->sessionMapper->findAllActive($documentId);
return array_map(function (Session $session) {
$result = $session->jsonSerialize();
$userManager = \OC::$server->getUserManager();
$user = $userManager->get($session->getUserId());
if ($user) {
$result['displayName'] = $user->getDisplayName();
}
$result['displayName'] = $this->userManager->getDisplayName($session->getUserId());
return $result;
}, $sessions);
}
Expand Down

0 comments on commit d0d8562

Please sign in to comment.