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

Only load routes of the app which is requested #13712

Merged
merged 2 commits into from
Aug 20, 2020

Conversation

MorrisJobke
Copy link
Member

@MorrisJobke MorrisJobke commented Jan 21, 2019

This removes ~70-90 ms on every request that involves a URLGenerator (in this case the stats are from the files default view). The total request too ~800ms so this is around 10%.

Before:
bildschirmfoto 2019-01-21 um 12 00 44

After:
bildschirmfoto 2019-01-21 um 12 01 24

Diff:
bildschirmfoto 2019-01-21 um 12 01 45

@nickvergessen
Copy link
Member

This will break activity app, because it has to generate links for various other Apps?

@MorrisJobke
Copy link
Member Author

This will break activity app, because it has to generate links for various other Apps?

Not really. It will only load the app for which the URLs where requested. So it does not open all the routes.php files of all apps at once, but if you request files.view.index then only the ones from the files app. Beside that there is often caching involved for the routes + their parameters.

But if you request then settings.user.index it will also load this. But before it always loaded for each generate() request that was not cached all the routes that are available.

Copy link
Member

@skjnldsv skjnldsv left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Tested and works fine.
Could not find any bug on various apps and core testing

@MorrisJobke
Copy link
Member Author

This might cause problem with OCS routes: https://github.com/nextcloud/server/pull/13714/files#diff-0c5fff2a86ede7f85fc3215283d957fcR113

Let me fix that.

@MorrisJobke
Copy link
Member Author

And I will also add some tests 🙈

@rullzer
Copy link
Member

rullzer commented Jan 21, 2019

Yeah ocs is different unforntuantly.

Did you also test this with the caching router? As I assume this will then have less effect.

@MorrisJobke MorrisJobke force-pushed the bugfix/noid/do-not-load-all-routes branch from 52812cc to 4fc464f Compare January 21, 2019 13:48
@MorrisJobke
Copy link
Member Author

Did you also test this with the caching router? As I assume this will then have less effect.

It was with caching enabled, but somehow still caused the generation of the URL for each request. Maybe something we should look into separately.

I fixed the OCS stuff and added tests. This is now ready to go in here. Also the OCS routes are just a weird hack and maybe require some more generalization but this is a different topic.

@MorrisJobke
Copy link
Member Author

I know why this failed. The logout URL has the request parameter in the URL:

$logoutUrl = $urlGenerator->linkToRouteAbsolute(
'core.login.logout',
[
'requesttoken' => \OCP\Util::callRegister(),
]
);

And thus the caching does not hit in:

$key = $this->context->getHost() . '#' . $this->context->getBaseUrl() . $name . sha1(json_encode($parameters)) . (int)$absolute;

@icewind1991
Copy link
Member

maybe worth adding a fallback to loading all routes?

I don't know if there is any code out there that messes with the route name format

@rullzer
Copy link
Member

rullzer commented Jan 22, 2019

I know why this failed. The logout URL has the request parameter in the URL:

server/lib/private/legacy/user.php

Lines 272 to 277 in bb86a8c
$logoutUrl = $urlGenerator->linkToRouteAbsolute(
'core.login.logout',
[
'requesttoken' => \OCP\Util::callRegister(),
]
);

And thus the caching does not hit in:

server/lib/private/Route/CachingRouter.php

Line 55 in c1e4f9f
$key = $this->context->getHost() . '#' . $this->context->getBaseUrl() . $name . sha1(json_encode($parameters)) . (int)$absolute;

Right. Yes and it needs to be there becuase it is a default get.
Maybe we should hack the caching router to handle this case better then. As it is special anyways.

@MorrisJobke MorrisJobke added 2. developing Work in progress and removed 3. to review Waiting for reviews labels Jan 23, 2019
Copy link
Member

@rullzer rullzer left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Added the fallback.

Lets get this in!

@rullzer rullzer added 3. to review Waiting for reviews and removed 2. developing Work in progress labels Feb 4, 2019
@MorrisJobke
Copy link
Member Author

Changes by @rullzer make sense 👍

@kesselb kesselb force-pushed the bugfix/noid/do-not-load-all-routes branch from 92ee378 to b2141b7 Compare December 9, 2019 11:18
@kesselb kesselb force-pushed the bugfix/noid/do-not-load-all-routes branch from b2141b7 to b0e53d4 Compare January 28, 2020 08:04
@kesselb kesselb added 3. to review Waiting for reviews and removed 2. developing Work in progress labels Jan 28, 2020
@rullzer rullzer mentioned this pull request Apr 4, 2020
80 tasks
@rullzer rullzer modified the milestones: Nextcloud 19, Nextcloud 20 Apr 7, 2020
@skjnldsv skjnldsv force-pushed the bugfix/noid/do-not-load-all-routes branch from b0e53d4 to bc853c2 Compare April 11, 2020 06:31
@MorrisJobke MorrisJobke force-pushed the bugfix/noid/do-not-load-all-routes branch 2 times, most recently from 6ab5975 to d3ae6af Compare July 5, 2020 16:15
@MorrisJobke
Copy link
Member Author

The change for the routes to be loaded via include instead of include_once is to allow it to properl load them in the unit tests as they re-initiate the routes during the same execution cycle.

@MorrisJobke
Copy link
Member Author

Should be ready for review now :)

@MorrisJobke MorrisJobke force-pushed the bugfix/noid/do-not-load-all-routes branch from d3ae6af to 26d55ed Compare July 5, 2020 16:20
Copy link
Member

@skjnldsv skjnldsv left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🐘

@rullzer
Copy link
Member

rullzer commented Jul 6, 2020

The change for the routes to be loaded via include instead of include_once is to allow it to properl load them in the unit tests as they re-initiate the routes during the same execution cycle.

So we modify the code to make the test pass? That doesn't sound right. From my understanding include once is correct here.

@MorrisJobke
Copy link
Member Author

The change for the routes to be loaded via include instead of include_once is to allow it to properl load them in the unit tests as they re-initiate the routes during the same execution cycle.

So we modify the code to make the test pass? That doesn't sound right. From my understanding include once is correct here.

Not in the context of changed behavior:

  • request files.SOMETHING
  • load only the files routes
  • return route
  • request files_SOMETHING
  • can't determine the app and thus need to load all routes
  • load all (this includes the files routes again) and because it was built with "it loads anything at once anyways" it is not meant for merging routes it will load all and overwrite the existing stuff in the "load all" step

But I'm fine with refine this and change that. On the other hand: we need to re-profile, because the causing issue seem to be solved as the timing doesn't improve that heavily anymore for me locally.

@MorrisJobke MorrisJobke force-pushed the bugfix/noid/do-not-load-all-routes branch from 26d55ed to df06251 Compare August 11, 2020 08:21
@MorrisJobke
Copy link
Member Author

So we modify the code to make the test pass? That doesn't sound right. From my understanding include once is correct here.

I reverted the change and instead streamlined the tests a bit (it initialized once the router per test case which then hits the limitations of this implementation due to the include_once - now the router is initialized only once).

@MorrisJobke MorrisJobke mentioned this pull request Aug 11, 2020
57 tasks
@MorrisJobke
Copy link
Member Author

I now properly injected the IRouter into the IURLGenerator. Now the tests are also properly separated.

@MorrisJobke MorrisJobke force-pushed the bugfix/noid/do-not-load-all-routes branch from c4d01b5 to 9b285f0 Compare August 11, 2020 21:41
* Add fallback to load all routes if needed
* Move partial loaded routes test to proper place

Signed-off-by: Morris Jobke <[email protected]>
@MorrisJobke MorrisJobke force-pushed the bugfix/noid/do-not-load-all-routes branch from 9b285f0 to 387cac4 Compare August 19, 2020 20:00
@MorrisJobke MorrisJobke added 4. to release Ready to be released and/or waiting for tests to finish and removed 3. to review Waiting for reviews labels Aug 19, 2020
@MorrisJobke MorrisJobke merged commit 6cdaadb into master Aug 20, 2020
@MorrisJobke MorrisJobke deleted the bugfix/noid/do-not-load-all-routes branch August 20, 2020 12:32
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
4. to release Ready to be released and/or waiting for tests to finish technical debt
Projects
None yet
Development

Successfully merging this pull request may close these issues.

6 participants