Skip to content

Commit d616b35

Browse files
committed
perf(index): Improve time to first byte
Signed-off-by: Marcel Klehr <mklehr@gmx.net>
1 parent b082652 commit d616b35

1 file changed

Lines changed: 17 additions & 7 deletions

File tree

lib/Controller/WebViewController.php

Lines changed: 17 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@
99
namespace OCA\Bookmarks\Controller;
1010

1111
use OCA\Bookmarks\AugmentedTemplateResponse;
12+
use OCA\Bookmarks\Db\BookmarkMapper;
1213
use OCA\Bookmarks\Db\Folder;
1314
use OCA\Bookmarks\Db\FolderMapper;
1415
use OCA\Bookmarks\Db\PublicFolder;
@@ -30,12 +31,14 @@
3031
use OCP\AppFramework\Http\NotFoundResponse;
3132
use OCP\AppFramework\Http\StreamResponse;
3233
use OCP\AppFramework\Http\Template\PublicTemplateResponse;
34+
use OCP\DB\Exception;
3335
use OCP\EventDispatcher\IEventDispatcher;
3436
use OCP\IConfig;
3537
use OCP\IL10N;
3638
use OCP\IRequest;
3739
use OCP\IURLGenerator;
3840
use OCP\IUserManager;
41+
use Psr\Log\LoggerInterface;
3942

4043
class WebViewController extends Controller {
4144
public function __construct(
@@ -51,11 +54,13 @@ public function __construct(
5154
private \OCA\Bookmarks\Controller\InternalFoldersController $folderController,
5255
private \OCA\Bookmarks\Controller\InternalBookmarkController $bookmarkController,
5356
private \OCA\Bookmarks\Controller\InternalTagsController $tagsController,
57+
private BookmarkMapper $bookmarkMapper,
5458
private UserSettingsService $userSettingsService,
5559
private SettingsService $settings,
5660
private IAppManager $appManager,
5761
private IConfig $config,
5862
private IEventDispatcher $eventDispatcher,
63+
private LoggerInterface $logger,
5964
) {
6065
parent::__construct($appName, $request);
6166
}
@@ -89,14 +94,19 @@ public function index(): AugmentedTemplateResponse {
8994
$res->setContentSecurityPolicy($policy);
9095

9196
$this->initialState->provideInitialState($this->appName, 'folders', $this->folderController->getFolders()->getData()['data']);
92-
$this->initialState->provideInitialState($this->appName, 'deletedFolders', $this->folderController->getDeletedFolders()->getData()['data']);
93-
$this->initialState->provideInitialState($this->appName, 'archivedCount', $this->bookmarkController->countArchived()->getData()['item']);
94-
$this->initialState->provideInitialState($this->appName, 'deletedCount', $this->bookmarkController->countDeleted()->getData()['item']);
95-
$this->initialState->provideInitialState($this->appName, 'duplicatedCount', $this->bookmarkController->countDuplicated()->getData()['item']);
96-
$this->initialState->provideInitialState($this->appName, 'unavailableCount', $this->bookmarkController->countUnavailable()->getData()['item']);
9797
$this->initialState->provideInitialState($this->appName, 'allCount', $this->bookmarkController->countBookmarks(-1)->getData()['item']);
98-
$this->initialState->provideInitialState($this->appName, 'allClicksCount', $this->bookmarkController->countAllClicks()->getData()['item']);
99-
$this->initialState->provideInitialState($this->appName, 'withClicksCount', $this->bookmarkController->countWithClicks()->getData()['item']);
98+
99+
try {
100+
$this->initialState->provideInitialState($this->appName, 'archivedCount', $this->bookmarkMapper->countArchived($this->userId));
101+
$this->initialState->provideInitialState($this->appName, 'deletedCount', $this->bookmarkMapper->countDeleted($this->userId));
102+
$this->initialState->provideInitialState($this->appName, 'duplicatedCount', $this->bookmarkMapper->countDuplicated($this->userId));
103+
$this->initialState->provideInitialState($this->appName, 'unavailableCount', $this->bookmarkMapper->countUnavailable($this->userId));
104+
$this->initialState->provideInitialState($this->appName, 'allClicksCount', $this->bookmarkMapper->countAllClicks($this->userId));
105+
$this->initialState->provideInitialState($this->appName, 'withClicksCount', $this->bookmarkMapper->countWithClicks($this->userId));
106+
} catch (Exception $e) {
107+
$this->logger->error($e->getMessage(), ['exception' => $e]);
108+
}
109+
100110
$this->initialState->provideInitialState($this->appName, 'tags', $this->tagsController->fullTags(true)->getData());
101111
$this->initialState->provideInitialState($this->appName, 'contextChatInstalled', $this->appManager->isEnabledForUser('context_chat'));
102112
$this->initialState->provideInitialState($this->appName, 'appStoreEnabled', $this->config->getSystemValueBool('appstoreenabled', true));

0 commit comments

Comments
 (0)