Skip to content

Commit

Permalink
Merge pull request #2805 from nextcloud/enh/noid/displayname-cache
Browse files Browse the repository at this point in the history
  • Loading branch information
juliusknorr authored Aug 24, 2022
2 parents c77ecc0 + d0d8562 commit 329dc33
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 329dc33

Please sign in to comment.