Skip to content

Optimize any request by eliminating redundant query for rootInfo and its contents - #27372

Merged
DeepDiver1975 merged 1 commit into
masterfrom
red_unuss_quer
Mar 20, 2017
Merged

DeepDiver1975 merged 1 commit into
masterfrom
red_unuss_quer

Conversation

@mrow4a

@mrow4a mrow4a commented Mar 13, 2017 •

Copy link
Copy Markdown
Contributor

#I found out that \OC::$server->getUserFolder(); will finish up calling $view->getFileInfo(''); and storing this information in its protected $fileInfo;, so we can get rid of one redundant FileInfo query here.

  • Optimisation
  • Unit tests

Effect of not calling $view->getFileInfo('') once again:
Non-shared:
selection_063

With shared files of various types:
selection_071
selection_086

On my local machine all tests passed. @DeepDiver1975 @PVince81 @butonic @felixboehm

@mention-bot

Copy link
Copy Markdown

@mrow4a, thanks for your PR! By analyzing the history of the files in this pull request, we identified @DeepDiver1975 and @PVince81 to be potential reviewers.

@mrow4a

mrow4a commented Mar 13, 2017

Copy link
Copy Markdown
Contributor Author

Can you verify that there is no case that would not work here?

@mrow4a mrow4a added this to the 10.0 milestone Mar 13, 2017
@mrow4a
mrow4a force-pushed the red_unuss_quer branch 2 times, most recently from c3757b9 to 1a22c23 Compare March 13, 2017 12:42
@PVince81

Copy link
Copy Markdown
Contributor

Looks fine, I can't think of anything that could go wrong here 👍

CI will confirm

if (!is_null($userFolder)) {
$rootInfo = $userFolder->getFileInfo();
} else {
$rootInfo = $view->getFileInfo('');

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

Shouldnt we move this condition somewhere inside getUserFolder? This code is not too elegant now, I have been more interested if it was breaking something eventually, but my general idea was to move it inside the logic below @DeepDiver1975 @PVince81

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

@PVince81 Some unit tests previously were not passing because userFolder was null, have no idea why it was returning null in some cases and we passed this null to other plugins, but calling $view->getFileInfo('') returns correctly

@mrow4a mrow4a Mar 13, 2017 •

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

Theoreticaly, this causes this which is nothing different then $view->getFileInfo('');

@mrow4a mrow4a Mar 13, 2017 •

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

WTF, ROOT calls get on itself which returns Folder, which then calls get which basicaly internaly calls return $this->root->get($this->getFullPath($path));, so basicaly root. It is very crazy or I am mistaken... It is like looking in the mirror holding another mirror

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Some unit tests previously were not passing because userFolder was null

Usually null is returned or PHPUnit mocks were one forgot to add an expectation and return value for a mocked method.

@mrow4a

mrow4a commented Mar 13, 2017 •

Copy link
Copy Markdown
Contributor Author

@PVince81 Hmm, actualy, I assume that if \OC::$server->getUserFolder(); returns null, it means that Null in $this->getUserSession()->getUser() happened. The function $root->getUserFolder($userId) cannot return NULL.

I understand that $view->getFileInfo('') is a backup case? Should it be? Maybe we should throw an exception?

Or is it signaling that \OC::$server->getUserFolder(); is not a Folder, but e.g. File? But this should be transparent in the logic below it, but it isnt and dont see a point to check it. Only Session allows returning NULL.

@PVince81

Copy link
Copy Markdown
Contributor

IIRC \OC::$server->getUserFolder(); would only return null if no user is logged in, for example when calling it from a public link page. This is when no arg is passed. If you pass a user id \OC::$server->getUserFolder($userId); it should not be null. If the user id doesn't exist I believe it will throw an exception.

@butonic

butonic commented Mar 14, 2017

Copy link
Copy Markdown
Contributor

Maybe we should throw an exception when no user is logged in (or the user does not exist ... but that should trigger an exception in a different place - when trying to get the user object - anyway). After all you are not supposed to call getUserFolder() whon no user is logged in. That justifies an exception IMNSHO. It forces developers to use a try catch and think about what to do when no user folder can be obtained...

@mrow4a

mrow4a commented Mar 14, 2017

Copy link
Copy Markdown
Contributor Author

@PVince81 What comments to add to this block, so it is transparent to the developer? Can you help here?

@PVince81

Copy link
Copy Markdown
Contributor

I don't know

@mrow4a

mrow4a commented Mar 14, 2017

Copy link
Copy Markdown
Contributor Author

I will do the test and throw an exception if we get null from somewhere else then user not logged in. If yes, we need to fix comments and maybe the code a little

@mrow4a
mrow4a force-pushed the red_unuss_quer branch 2 times, most recently from e7aac75 to 507e947 Compare March 14, 2017 10:45
@mrow4a

mrow4a commented Mar 14, 2017

Copy link
Copy Markdown
Contributor Author

Yep, this is only possible if user is NULL and then it returns NULL. We can probably do it in try-catch or just leave as it is.

@mrow4a
mrow4a force-pushed the red_unuss_quer branch 5 times, most recently from 704d41f to d281e59 Compare March 14, 2017 23:34
@mrow4a

mrow4a commented Mar 15, 2017

Copy link
Copy Markdown
Contributor Author

@butonic @PVince81 can we merge?

@mrow4a

mrow4a commented Mar 15, 2017

Copy link
Copy Markdown
Contributor Author

@DeepDiver1975 I think I need to refactor it to get rid of redundant queries from Folder/Directory logic

@mrow4a
mrow4a force-pushed the red_unuss_quer branch 2 times, most recently from d8c3689 to 5081670 Compare March 15, 2017 14:16
@mrow4a

mrow4a commented Mar 15, 2017 •

Copy link
Copy Markdown
Contributor Author

Benchmark update on the new commit. Lets see if this passes all the existing unit/integration tests, and then I need to add few more to cover the code.

@mrow4a mrow4a changed the title Optimize any request by eliminating redundant query for rootInfo Optimize any request by eliminating redundant query for rootInfo and its contents Mar 15, 2017
@mrow4a
mrow4a force-pushed the red_unuss_quer branch 2 times, most recently from cf444c2 to eb6486a Compare March 16, 2017 11:25
@mrow4a

mrow4a commented Mar 16, 2017

Copy link
Copy Markdown
Contributor Author

@DeepDiver1975 @PVince81 Original implementation of https://github.com/owncloud/core/pull/27284/files SharesPlugin was using getDirectoryListing, duplicating number of the same queries. getChildren() internaly will anyway call View for directoryContents, and implements caching internaly, thus forcing SharesPlugin to use getChildren reduces number of queries.

Call only getChildren to avoid excessive calls to DB
@mrow4a

mrow4a commented Mar 20, 2017 •

Copy link
Copy Markdown
Contributor Author

Any input on this PR? This not only gets rid of the redundant query for Root, but also avoid using $this->view->getDirectoryContents from both Folder and Directory, avoiding doubled queries to DB (Directory is internaly caching result from view). With this PR, SharedPlugin will use Directory (as Tag and Core Plugins) instead of Folder.

@DeepDiver1975
DeepDiver1975 merged commit 26d768b into master Mar 20, 2017
@DeepDiver1975
DeepDiver1975 deleted the red_unuss_quer branch March 20, 2017 07:50
@lock

lock Bot commented Aug 3, 2019

Copy link
Copy Markdown

This thread has been automatically locked since there has not been any recent activity after it was closed. Please open a new issue for related bugs.

@lock lock Bot locked as resolved and limited conversation to collaborators Aug 3, 2019
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

5 participants