mirror of
https://github.com/nextcloud/server.git
synced 2026-04-21 14:23:17 -04:00
perf(files): Do not block files page load with server-side favorites retrieval
Co-authored-by: Ferdinand Thiessen <opensource@fthiessen.de> Signed-off-by: Christopher Ng <chrng8@gmail.com>
This commit is contained in:
parent
0b5c424f3a
commit
83ae86271c
2 changed files with 16 additions and 63 deletions
|
|
@ -8,7 +8,6 @@
|
|||
namespace OCA\Files\Controller;
|
||||
|
||||
use OC\Files\FilenameValidator;
|
||||
use OCA\Files\Activity\Helper;
|
||||
use OCA\Files\AppInfo\Application;
|
||||
use OCA\Files\Event\LoadAdditionalScriptsEvent;
|
||||
use OCA\Files\Event\LoadSearchPlugins;
|
||||
|
|
@ -54,7 +53,6 @@ class ViewController extends Controller {
|
|||
private IUserSession $userSession,
|
||||
private IAppManager $appManager,
|
||||
private IRootFolder $rootFolder,
|
||||
private Helper $activityHelper,
|
||||
private IInitialState $initialState,
|
||||
private ITemplateManager $templateManager,
|
||||
private UserConfig $userConfig,
|
||||
|
|
@ -146,18 +144,6 @@ class ViewController extends Controller {
|
|||
|
||||
$userId = $this->userSession->getUser()->getUID();
|
||||
|
||||
// Get all the user favorites to create a submenu
|
||||
try {
|
||||
$userFolder = $this->rootFolder->getUserFolder($userId);
|
||||
$favElements = $this->activityHelper->getFavoriteNodes($userId, true);
|
||||
$favElements = array_map(fn (Folder $node) => [
|
||||
'fileid' => $node->getId(),
|
||||
'path' => $userFolder->getRelativePath($node->getPath()),
|
||||
], $favElements);
|
||||
} catch (\RuntimeException $e) {
|
||||
$favElements = [];
|
||||
}
|
||||
|
||||
// If the file doesn't exists in the folder and
|
||||
// exists in only one occurrence, redirect to that file
|
||||
// in the correct folder
|
||||
|
|
@ -187,7 +173,6 @@ class ViewController extends Controller {
|
|||
$this->initialState->provideInitialState('storageStats', $storageInfo);
|
||||
$this->initialState->provideInitialState('config', $this->userConfig->getConfigs());
|
||||
$this->initialState->provideInitialState('viewConfigs', $this->viewConfig->getConfigs());
|
||||
$this->initialState->provideInitialState('favoriteFolders', $favElements);
|
||||
|
||||
// File sorting user config
|
||||
$filesSortingConfig = json_decode($this->config->getUserValue($userId, 'files', 'files_sorting_configs', '{}'), true);
|
||||
|
|
|
|||
|
|
@ -8,7 +8,6 @@
|
|||
namespace OCA\Files\Tests\Controller;
|
||||
|
||||
use OC\Files\FilenameValidator;
|
||||
use OCA\Files\Activity\Helper;
|
||||
use OCA\Files\Controller\ViewController;
|
||||
use OCA\Files\Service\UserConfig;
|
||||
use OCA\Files\Service\ViewConfig;
|
||||
|
|
@ -26,7 +25,7 @@ use OCP\IRequest;
|
|||
use OCP\IURLGenerator;
|
||||
use OCP\IUser;
|
||||
use OCP\IUserSession;
|
||||
use OCP\Share\IManager;
|
||||
use PHPUnit\Framework\MockObject\MockObject;
|
||||
use Test\TestCase;
|
||||
|
||||
/**
|
||||
|
|
@ -35,38 +34,21 @@ use Test\TestCase;
|
|||
* @package OCA\Files\Tests\Controller
|
||||
*/
|
||||
class ViewControllerTest extends TestCase {
|
||||
/** @var IRequest|\PHPUnit\Framework\MockObject\MockObject */
|
||||
private $request;
|
||||
/** @var IURLGenerator|\PHPUnit\Framework\MockObject\MockObject */
|
||||
private $urlGenerator;
|
||||
/** @var IL10N */
|
||||
private $l10n;
|
||||
/** @var IConfig|\PHPUnit\Framework\MockObject\MockObject */
|
||||
private $config;
|
||||
/** @var IEventDispatcher */
|
||||
private $eventDispatcher;
|
||||
/** @var ViewController|\PHPUnit\Framework\MockObject\MockObject */
|
||||
private $viewController;
|
||||
/** @var IUser|\PHPUnit\Framework\MockObject\MockObject */
|
||||
private $user;
|
||||
/** @var IUserSession|\PHPUnit\Framework\MockObject\MockObject */
|
||||
private $userSession;
|
||||
/** @var IAppManager|\PHPUnit\Framework\MockObject\MockObject */
|
||||
private $appManager;
|
||||
/** @var IRootFolder|\PHPUnit\Framework\MockObject\MockObject */
|
||||
private $rootFolder;
|
||||
/** @var Helper|\PHPUnit\Framework\MockObject\MockObject */
|
||||
private $activityHelper;
|
||||
/** @var IInitialState|\PHPUnit\Framework\MockObject\MockObject */
|
||||
private $initialState;
|
||||
/** @var ITemplateManager|\PHPUnit\Framework\MockObject\MockObject */
|
||||
private $templateManager;
|
||||
/** @var IManager|\PHPUnit\Framework\MockObject\MockObject */
|
||||
private $shareManager;
|
||||
/** @var UserConfig|\PHPUnit\Framework\MockObject\MockObject */
|
||||
private $userConfig;
|
||||
/** @var ViewConfig|\PHPUnit\Framework\MockObject\MockObject */
|
||||
private $viewConfig;
|
||||
private IRequest&MockObject $request;
|
||||
private IURLGenerator&MockObject $urlGenerator;
|
||||
private IL10N&MockObject $l10n;
|
||||
private IConfig&MockObject $config;
|
||||
private IEventDispatcher $eventDispatcher;
|
||||
private IUser&MockObject $user;
|
||||
private IUserSession&MockObject $userSession;
|
||||
private IAppManager&MockObject $appManager;
|
||||
private IRootFolder&MockObject $rootFolder;
|
||||
private IInitialState&MockObject $initialState;
|
||||
private ITemplateManager&MockObject $templateManager;
|
||||
private UserConfig&MockObject $userConfig;
|
||||
private ViewConfig&MockObject $viewConfig;
|
||||
|
||||
private ViewController&MockObject $viewController;
|
||||
|
||||
protected function setUp(): void {
|
||||
parent::setUp();
|
||||
|
|
@ -85,7 +67,6 @@ class ViewControllerTest extends TestCase {
|
|||
->method('getUser')
|
||||
->willReturn($this->user);
|
||||
$this->rootFolder = $this->getMockBuilder('\OCP\Files\IRootFolder')->getMock();
|
||||
$this->activityHelper = $this->createMock(Helper::class);
|
||||
$this->initialState = $this->createMock(IInitialState::class);
|
||||
$this->templateManager = $this->createMock(ITemplateManager::class);
|
||||
$this->userConfig = $this->createMock(UserConfig::class);
|
||||
|
|
@ -104,7 +85,6 @@ class ViewControllerTest extends TestCase {
|
|||
$this->userSession,
|
||||
$this->appManager,
|
||||
$this->rootFolder,
|
||||
$this->activityHelper,
|
||||
$this->initialState,
|
||||
$this->templateManager,
|
||||
$this->userConfig,
|
||||
|
|
@ -162,18 +142,6 @@ class ViewControllerTest extends TestCase {
|
|||
$policy->addAllowedFrameDomain('\'self\'');
|
||||
$expected->setContentSecurityPolicy($policy);
|
||||
|
||||
$this->activityHelper->method('getFavoriteFilePaths')
|
||||
->with($this->user->getUID())
|
||||
->willReturn([
|
||||
'item' => [],
|
||||
'folders' => [
|
||||
'/test1',
|
||||
'/test2/',
|
||||
'/test3/sub4',
|
||||
'/test5/sub6/',
|
||||
],
|
||||
]);
|
||||
|
||||
$this->assertEquals($expected, $this->viewController->index('MyDir', 'MyView'));
|
||||
}
|
||||
|
||||
|
|
|
|||
Loading…
Reference in a new issue