Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Use displayname cache for fetching session data #2805

Merged
merged 1 commit into from
Aug 24, 2022
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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