Skip to content

Commit eeb9f93

Browse files
authored
Merge pull request #60345 from nextcloud/backport/59753/stable33
[stable33] perf(share): Remove useless order by id
2 parents 9b74533 + d098916 commit eeb9f93

2 files changed

Lines changed: 15 additions & 9 deletions

File tree

lib/private/Share20/DefaultShareProvider.php

Lines changed: 12 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -381,8 +381,7 @@ public function getChildren(IShare $parent): array {
381381
], IQueryBuilder::PARAM_INT_ARRAY)
382382
)
383383
)
384-
->andWhere($qb->expr()->in('item_type', $qb->createNamedParameter(['file', 'folder'], IQueryBuilder::PARAM_STR_ARRAY)))
385-
->orderBy('id');
384+
->andWhere($qb->expr()->in('item_type', $qb->createNamedParameter(['file', 'folder'], IQueryBuilder::PARAM_STR_ARRAY)));
386385

387386
$cursor = $qb->executeQuery();
388387
while ($data = $cursor->fetch()) {
@@ -666,8 +665,6 @@ private function getSharesInFolderInternal(?string $userId, Folder $node, ?bool
666665
)
667666
);
668667

669-
$qb->orderBy('id');
670-
671668
$shares = [];
672669

673670
$chunks = array_chunk($childMountRootIds, 1000);
@@ -725,7 +722,9 @@ public function getSharesBy($userId, $shareType, $node, $reshares, $limit, $offs
725722
}
726723

727724
$qb->setFirstResult($offset);
728-
$qb->orderBy('id');
725+
if ($offset !== 0 || $limit !== -1) {
726+
$qb->orderBy('id');
727+
}
729728

730729
$cursor = $qb->executeQuery();
731730
$shares = [];
@@ -794,7 +793,6 @@ public function getSharesByPath(Node $path) {
794793
->andWhere($qb->expr()->eq('file_source', $qb->createNamedParameter($path->getId())))
795794
->andWhere($qb->expr()->in('share_type', $qb->createNamedParameter([IShare::TYPE_USER, IShare::TYPE_GROUP, IShare::TYPE_LINK], IQueryBuilder::PARAM_INT_ARRAY)))
796795
->andWhere($qb->expr()->in('item_type', $qb->createNamedParameter(['file', 'folder'], IQueryBuilder::PARAM_STR_ARRAY)))
797-
->orderBy('id', 'ASC')
798796
->executeQuery();
799797

800798
$shares = [];
@@ -887,8 +885,10 @@ private function _getSharedWith(
887885
->leftJoin('s', 'filecache', 'f', $qb->expr()->eq('s.file_source', 'f.fileid'))
888886
->leftJoin('f', 'storages', 'st', $qb->expr()->eq('f.storage', 'st.numeric_id'));
889887

890-
// Order by id
891-
$qb->orderBy('s.id');
888+
if ($offset !== 0 || $limit !== -1) {
889+
// Order by id
890+
$qb->orderBy('s.id');
891+
}
892892

893893
// Set limit and offset
894894
if ($limit !== -1) {
@@ -957,9 +957,12 @@ private function _getSharedWith(
957957
->from('share', 's')
958958
->leftJoin('s', 'filecache', 'f', $qb->expr()->eq('s.file_source', 'f.fileid'))
959959
->leftJoin('f', 'storages', 'st', $qb->expr()->eq('f.storage', 'st.numeric_id'))
960-
->orderBy('s.id')
961960
->setFirstResult(0);
962961

962+
if ($offset !== 0 || $limit !== -1) {
963+
$qb->orderBy('s.id');
964+
}
965+
963966
if ($limit !== -1) {
964967
$qb->setMaxResults($limit - count($shares));
965968
}

tests/lib/Share20/DefaultShareProviderTest.php

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -660,6 +660,7 @@ public function testGetChildren(): void {
660660
$share->method('getId')->willReturn($id);
661661

662662
$children = $this->provider->getChildren($share);
663+
usort($children, fn (IShare $a, IShare $b) => $a->getId() <=> $b->getId());
663664

664665
$this->assertCount(2, $children);
665666

@@ -2640,6 +2641,7 @@ public function testGetSharesInFolder(): void {
26402641
$this->assertSame(IShare::TYPE_USER, $file_shares[0]->getShareType());
26412642

26422643
$folder_shares = $result[$folder2->getId()];
2644+
usort($folder_shares, fn (IShare $a, IShare $b) => $a->getId() <=> $b->getId());
26432645
$this->assertCount(2, $folder_shares);
26442646
$this->assertSame($folder2->getId(), $folder_shares[0]->getNodeId());
26452647
$this->assertSame($folder2->getId(), $folder_shares[1]->getNodeId());
@@ -3100,6 +3102,7 @@ public function testGetSharesByPath(): void {
31003102
->willReturn(1);
31013103

31023104
$shares = $this->provider->getSharesByPath($node);
3105+
usort($shares, fn (IShare $a, IShare $b) => $a->getId() <=> $b->getId());
31033106
$this->assertCount(3, $shares);
31043107

31053108
$this->assertEquals($id1, $shares[0]->getId());

0 commit comments

Comments
 (0)