From 3d0e8a5002c36e08bb0c6a2d009d4535195be98b Mon Sep 17 00:00:00 2001 From: Carl Schwan Date: Fri, 11 Feb 2022 22:26:25 +0100 Subject: [PATCH 1/2] Don't redirect when loading files index page Currently we are redirecting from ?dir=/&fileid=2 to ?dir=/. This is an issue because we then need to load two pages with full file system setup and authentification instead of one and the assets won't start loading until the second page is delivered to the user. Additionally when loading ?dir=/, we then change the url back to ?dir=/&fileid=2 (without reload) so that the next time we load the page again we do the same thing again. Depending on the speed of the server and internet connection we can save 100ms to 400ms, improving the user experience. Signed-off-by: Carl Schwan --- apps/files/lib/Controller/ViewController.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/apps/files/lib/Controller/ViewController.php b/apps/files/lib/Controller/ViewController.php index fd84998769ddf..dbb852ffeb846 100644 --- a/apps/files/lib/Controller/ViewController.php +++ b/apps/files/lib/Controller/ViewController.php @@ -184,7 +184,7 @@ public function showFile(string $fileid = null, int $openfile = 1): Response { * @throws NotFoundException */ public function index($dir = '', $view = '', $fileid = null, $fileNotFound = false, $openfile = null) { - if ($fileid !== null) { + if ($fileid !== null && $dir === '') { try { return $this->redirectToFile($fileid); } catch (NotFoundException $e) { From 9bc0e01d2453a812a5c4b84289dbafc72bf5c45e Mon Sep 17 00:00:00 2001 From: Carl Schwan Date: Mon, 21 Feb 2022 11:35:22 +0100 Subject: [PATCH 2/2] Redirection now only happens when dir is empty Otherwise dir it's just ignored and fileid is used Signed-off-by: Carl Schwan --- apps/files/tests/Controller/ViewControllerTest.php | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/apps/files/tests/Controller/ViewControllerTest.php b/apps/files/tests/Controller/ViewControllerTest.php index d7b298d9e844e..33467f1464b4f 100644 --- a/apps/files/tests/Controller/ViewControllerTest.php +++ b/apps/files/tests/Controller/ViewControllerTest.php @@ -459,7 +459,7 @@ public function testShowFileRouteWithFolder() { ->willReturn('/apps/files/?dir=/test/sub'); $expected = new Http\RedirectResponse('/apps/files/?dir=/test/sub'); - $this->assertEquals($expected, $this->viewController->index('/whatever', '', '123')); + $this->assertEquals($expected, $this->viewController->index('', '', '123')); } public function testShowFileRouteWithFile() { @@ -499,7 +499,7 @@ public function testShowFileRouteWithFile() { ->willReturn('/apps/files/?dir=/test/sub&scrollto=somefile.txt'); $expected = new Http\RedirectResponse('/apps/files/?dir=/test/sub&scrollto=somefile.txt'); - $this->assertEquals($expected, $this->viewController->index('/whatever', '', '123')); + $this->assertEquals($expected, $this->viewController->index('', '', '123')); } public function testShowFileRouteWithInvalidFileId() { @@ -519,7 +519,7 @@ public function testShowFileRouteWithInvalidFileId() { ->with('files.view.index', ['fileNotFound' => true]) ->willReturn('redirect.url'); - $response = $this->viewController->index('MyDir', 'MyView', '123'); + $response = $this->viewController->index('', 'MyView', '123'); $this->assertInstanceOf('OCP\AppFramework\Http\RedirectResponse', $response); $this->assertEquals('redirect.url', $response->getRedirectURL()); } @@ -576,6 +576,6 @@ public function testShowFileRouteWithTrashedFile() { ->willReturn('/apps/files/?view=trashbin&dir=/test.d1462861890/sub&scrollto=somefile.txt'); $expected = new Http\RedirectResponse('/apps/files/?view=trashbin&dir=/test.d1462861890/sub&scrollto=somefile.txt'); - $this->assertEquals($expected, $this->viewController->index('/whatever', '', '123')); + $this->assertEquals($expected, $this->viewController->index('', '', '123')); } }