Skip to content
GitLab
Projects
Groups
Snippets
Help
Loading...
Help
What's new
7
Help
Support
Community forum
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in
Toggle navigation
Open sidebar
die_coolen_jungs
our_own_cloud_project
Commits
26d768b8
Commit
26d768b8
authored
Mar 20, 2017
by
Piotr Mrówczyński
Committed by
Thomas Müller
Mar 20, 2017
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Optimize any request by eliminating redundant query for rootInfo. (#27372)
Call only getChildren to avoid excessive calls to DB
parent
da389acc
Changes
4
Hide whitespace changes
Inline
Side-by-side
Showing
4 changed files
with
24 additions
and
59 deletions
+24
-59
apps/dav/lib/Connector/Sabre/ServerFactory.php
apps/dav/lib/Connector/Sabre/ServerFactory.php
+15
-8
apps/dav/lib/Connector/Sabre/SharesPlugin.php
apps/dav/lib/Connector/Sabre/SharesPlugin.php
+6
-9
apps/dav/lib/Server.php
apps/dav/lib/Server.php
+0
-1
apps/dav/tests/unit/Connector/Sabre/SharesPluginTest.php
apps/dav/tests/unit/Connector/Sabre/SharesPluginTest.php
+3
-41
No files found.
apps/dav/lib/Connector/Sabre/ServerFactory.php
View file @
26d768b8
...
...
@@ -110,9 +110,9 @@ class ServerFactory {
// Some WebDAV clients do require Class 2 WebDAV support (locking), since
// we do not provide locking we emulate it using a fake locking plugin.
if
(
$this
->
request
->
isUserAgent
([
'/WebDAVFS/'
,
'/Microsoft Office OneNote 2013/'
,
'/Microsoft-WebDAV-MiniRedir/'
,
'/WebDAVFS/'
,
'/Microsoft Office OneNote 2013/'
,
'/Microsoft-WebDAV-MiniRedir/'
,
]))
{
$server
->
addPlugin
(
new
\
OCA\DAV\Connector\Sabre\FakeLockerPlugin
());
}
...
...
@@ -124,18 +124,26 @@ class ServerFactory {
// wait with registering these until auth is handled and the filesystem is setup
$server
->
on
(
'beforeMethod'
,
function
()
use
(
$server
,
$objectTree
,
$viewCallBack
)
{
// ensure the skeleton is copied
// Try to obtain User Folder
$userFolder
=
\
OC
::
$server
->
getUserFolder
();
/** @var \OC\Files\View $view */
$view
=
$viewCallBack
(
$server
);
$rootInfo
=
$view
->
getFileInfo
(
''
);
if
(
!
is_null
(
$userFolder
))
{
// User folder exists and user is active and not anonymous
$rootInfo
=
$userFolder
->
getFileInfo
();
}
else
{
// User is anonymous or inactive, we need to get root info
$rootInfo
=
$view
->
getFileInfo
(
''
);
}
// Create ownCloud
Dir
// Create ownCloud
Root
if
(
$rootInfo
->
getType
()
===
'dir'
)
{
$root
=
new
\
OCA\DAV\Connector\Sabre\Directory
(
$view
,
$rootInfo
,
$objectTree
);
}
else
{
$root
=
new
\
OCA\DAV\Connector\Sabre\File
(
$view
,
$rootInfo
);
}
$objectTree
->
init
(
$root
,
$view
,
$this
->
mountManager
);
$server
->
addPlugin
(
...
...
@@ -154,7 +162,6 @@ class ServerFactory {
$server
->
addPlugin
(
new
\
OCA\DAV\Connector\Sabre\SharesPlugin
(
$objectTree
,
$this
->
userSession
,
$userFolder
,
\
OC
::
$server
->
getShareManager
()
));
$server
->
addPlugin
(
new
\
OCA\DAV\Connector\Sabre\CommentPropertiesPlugin
(
\
OC
::
$server
->
getCommentsManager
(),
$this
->
userSession
));
...
...
@@ -183,4 +190,4 @@ class ServerFactory {
},
30
);
// priority 30: after auth (10) and acl(20), before lock(50) and handling the request
return
$server
;
}
}
}
\ No newline at end of file
apps/dav/lib/Connector/Sabre/SharesPlugin.php
View file @
26d768b8
...
...
@@ -74,12 +74,10 @@ class SharesPlugin extends \Sabre\DAV\ServerPlugin {
public
function
__construct
(
\
Sabre\DAV\Tree
$tree
,
IUserSession
$userSession
,
\
OCP\Files\Folder
$userFolder
,
\
OCP\Share\IManager
$shareManager
)
{
$this
->
tree
=
$tree
;
$this
->
shareManager
=
$shareManager
;
$this
->
userFolder
=
$userFolder
;
$this
->
userId
=
$userSession
->
getUser
()
->
getUID
();
$this
->
cachedShareTypes
=
[];
}
...
...
@@ -168,11 +166,10 @@ class SharesPlugin extends \Sabre\DAV\ServerPlugin {
&&
$propFind
->
getDepth
()
!==
0
&&
!
is_null
(
$propFind
->
getStatus
(
self
::
SHARETYPES_PROPERTYNAME
))
)
{
$folderNode
=
$this
->
userFolder
->
get
(
$sabreNode
->
getPath
());
$children
=
$folderNode
->
getDirectoryListing
();
$children
=
$sabreNode
->
getChildren
();
// Get ID of parent folder
$folderNodeID
=
intval
(
$folder
Node
->
getId
()
)
;
$folderNodeID
=
$sabre
Node
->
getId
();
$nodeIdsArray
=
[
$folderNodeID
];
// Initialize share types array for this node in case there would be no shares for this node
...
...
@@ -181,13 +178,13 @@ class SharesPlugin extends \Sabre\DAV\ServerPlugin {
// Get IDs for all children of the parent folder
foreach
(
$children
as
$childNode
)
{
// Ensure that they are of File or Folder type
if
(
!
(
$childNode
instanceof
\
OC
P\Files\File
)
&&
!
(
$childNode
instanceof
\
OC
P\Files\Folder
))
{
if
(
!
(
$childNode
instanceof
\
OC
A\DAV\Connector\Sabre\Directory
)
&&
!
(
$childNode
instanceof
\
OC
A\DAV\Connector\Sabre\File
))
{
return
;
}
// Put node ID into an array and initialize cache for it
$nodeId
=
intval
(
$childNode
->
getId
()
)
;
$nodeId
=
$childNode
->
getId
();
array_push
(
$nodeIdsArray
,
$nodeId
);
// Initialize share types array for this node in case there would be no shares for this node
...
...
@@ -207,7 +204,7 @@ class SharesPlugin extends \Sabre\DAV\ServerPlugin {
$shareTypesHash
=
$this
->
cachedShareTypes
[
$sabreNode
->
getId
()];
}
else
{
// Share types for this node not in cache, obtain if any
$nodeId
=
$
this
->
userFolder
->
get
(
$sabreNode
->
getPath
())
->
getId
();
$nodeId
=
$
sabreNode
->
getId
();
$returnedShares
=
$this
->
getSharesForNodeIds
([
$nodeId
]);
// Initialize share types for this node and obtain share types hash if any
...
...
apps/dav/lib/Server.php
View file @
26d768b8
...
...
@@ -188,7 +188,6 @@ class Server {
$this
->
server
->
addPlugin
(
new
SharesPlugin
(
$this
->
server
->
tree
,
$userSession
,
$userFolder
,
\
OC
::
$server
->
getShareManager
()
));
$this
->
server
->
addPlugin
(
new
CommentPropertiesPlugin
(
...
...
apps/dav/tests/unit/Connector/Sabre/SharesPluginTest.php
View file @
26d768b8
...
...
@@ -69,12 +69,9 @@ class SharesPluginTest extends \Test\TestCase {
->
method
(
'getUser'
)
->
will
(
$this
->
returnValue
(
$user
));
$this
->
userFolder
=
$this
->
createMock
(
'\OCP\Files\Folder'
);
$this
->
plugin
=
new
\
OCA\DAV\Connector\Sabre\SharesPlugin
(
$this
->
tree
,
$userSession
,
$this
->
userFolder
,
$this
->
shareManager
);
$this
->
plugin
->
initialize
(
$this
->
server
);
...
...
@@ -90,20 +87,6 @@ class SharesPluginTest extends \Test\TestCase {
$sabreNode
->
expects
(
$this
->
any
())
->
method
(
'getId'
)
->
will
(
$this
->
returnValue
(
123
));
$sabreNode
->
expects
(
$this
->
once
())
->
method
(
'getPath'
)
->
will
(
$this
->
returnValue
(
'/subdir'
));
// node API nodes
$node
=
$this
->
createMock
(
'\OCP\Files\Folder'
);
$node
->
expects
(
$this
->
any
())
->
method
(
'getId'
)
->
will
(
$this
->
returnValue
(
123
));
$this
->
userFolder
->
expects
(
$this
->
once
())
->
method
(
'get'
)
->
with
(
'/subdir'
)
->
will
(
$this
->
returnValue
(
$node
));
$requestedShareTypes
=
[
\
OCP\Share
::
SHARE_TYPE_USER
,
...
...
@@ -179,34 +162,13 @@ class SharesPluginTest extends \Test\TestCase {
->
method
(
'getId'
)
->
will
(
$this
->
returnValue
(
123
));
// never, because we use getDirectoryListing from the Node API instead
$sabreNode
->
expects
(
$this
->
never
())
->
method
(
'getChildren'
);
$sabreNode
->
expects
(
$this
->
once
())
->
method
(
'getChildren'
)
->
will
(
$this
->
returnValue
([
$sabreNode1
,
$sabreNode2
]));
$sabreNode
->
expects
(
$this
->
any
())
->
method
(
'getPath'
)
->
will
(
$this
->
returnValue
(
'/subdir'
));
// node API nodes
$node
=
$this
->
createMock
(
'\OCP\Files\Folder'
);
$node
->
expects
(
$this
->
any
())
->
method
(
'getId'
)
->
will
(
$this
->
returnValue
(
123
));
$node1
=
$this
->
createMock
(
'\OCP\Files\File'
);
$node1
->
expects
(
$this
->
any
())
->
method
(
'getId'
)
->
will
(
$this
->
returnValue
(
111
));
$node2
=
$this
->
createMock
(
'\OCP\Files\File'
);
$node2
->
expects
(
$this
->
any
())
->
method
(
'getId'
)
->
will
(
$this
->
returnValue
(
222
));
$node
->
expects
(
$this
->
once
())
->
method
(
'getDirectoryListing'
)
->
will
(
$this
->
returnValue
([
$node1
,
$node2
]));
$this
->
userFolder
->
expects
(
$this
->
once
())
->
method
(
'get'
)
->
with
(
'/subdir'
)
->
will
(
$this
->
returnValue
(
$node
));
$requestedShareTypes
=
[
\
OCP\Share
::
SHARE_TYPE_USER
,
\
OCP\Share
::
SHARE_TYPE_GROUP
,
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
.
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment