perf: reduce db requests

pull/63/head
sualko 2020-06-04 10:25:51 +02:00
parent 0074f717ea
commit bcc483b918
1 changed files with 16 additions and 2 deletions

View File

@ -3,6 +3,7 @@ namespace OCA\BigBlueButton\Controller;
use OCA\BigBlueButton\BigBlueButton\API; use OCA\BigBlueButton\BigBlueButton\API;
use OCA\BigBlueButton\BigBlueButton\Presentation; use OCA\BigBlueButton\BigBlueButton\Presentation;
use OCA\BigBlueButton\Db\Room;
use OCA\BigBlueButton\NotFoundException; use OCA\BigBlueButton\NotFoundException;
use OCP\AppFramework\Http\RedirectResponse; use OCP\AppFramework\Http\RedirectResponse;
use OCP\IRequest; use OCP\IRequest;
@ -18,6 +19,9 @@ class JoinController extends Controller
/** @var string */ /** @var string */
protected $token; protected $token;
/** @var Room */
protected $room;
/** @var RoomService */ /** @var RoomService */
private $service; private $service;
@ -50,11 +54,12 @@ class JoinController extends Controller
public function setToken(string $token) public function setToken(string $token)
{ {
$this->token = $token; $this->token = $token;
$this->room = null;
} }
public function isValidToken(): bool public function isValidToken(): bool
{ {
$room = $this->service->findByUid($this->token); $room = $this->getRoom();
return $room !== null; return $room !== null;
} }
@ -65,7 +70,7 @@ class JoinController extends Controller
*/ */
public function index($displayname, $u = '', $filename = '') public function index($displayname, $u = '', $filename = '')
{ {
$room = $this->service->findByUid($this->token); $room = $this->getRoom();
if ($room === null) { if ($room === null) {
throw new NotFoundException(); throw new NotFoundException();
@ -110,4 +115,13 @@ class JoinController extends Controller
$response->getContentSecurityPolicy()->addAllowedFormActionDomain(($parsedApiUrl['scheme'] ?: 'https') . '://' . $parsedApiUrl['host']); $response->getContentSecurityPolicy()->addAllowedFormActionDomain(($parsedApiUrl['scheme'] ?: 'https') . '://' . $parsedApiUrl['host']);
} }
private function getRoom(): Room
{
if ($this->room === null) {
$this->room = $this->service->findByUid($this->token);
}
return $this->room;
}
} }