Skip to content

Commit fcb956b

Browse files
authored
Merge pull request #59753 from nextcloud/work/carl/remove-orderById
perf(share): Remove useless order by id
2 parents 91762ea + 3dbefe8 commit fcb956b

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
@@ -393,8 +393,7 @@ public function getChildren(IShare $parent): array {
393393
], IQueryBuilder::PARAM_INT_ARRAY)
394394
)
395395
)
396-
->andWhere($qb->expr()->in('item_type', $qb->createNamedParameter(['file', 'folder'], IQueryBuilder::PARAM_STR_ARRAY)))
397-
->orderBy('id');
396+
->andWhere($qb->expr()->in('item_type', $qb->createNamedParameter(['file', 'folder'], IQueryBuilder::PARAM_STR_ARRAY)));
398397

399398
$cursor = $qb->executeQuery();
400399
while ($data = $cursor->fetch()) {
@@ -684,8 +683,6 @@ private function getSharesInFolderInternal(?string $userId, Folder $node, ?bool
684683
)
685684
);
686685

687-
$qb->orderBy('id');
688-
689686
$shares = [];
690687

691688
$chunks = array_chunk($childMountRootIds, 1000);
@@ -744,7 +741,9 @@ public function getSharesBy($userId, $shareType, $node, $reshares, $limit, $offs
744741
}
745742

746743
$qb->setFirstResult($offset);
747-
$qb->orderBy('id');
744+
if ($offset !== 0 || $limit !== -1) {
745+
$qb->orderBy('id');
746+
}
748747

749748
$cursor = $qb->executeQuery();
750749
$shares = [];
@@ -815,7 +814,6 @@ public function getSharesByPath(Node $path) {
815814
->andWhere($qb->expr()->eq('file_source', $qb->createNamedParameter($path->getId())))
816815
->andWhere($qb->expr()->in('share_type', $qb->createNamedParameter([IShare::TYPE_USER, IShare::TYPE_GROUP, IShare::TYPE_LINK], IQueryBuilder::PARAM_INT_ARRAY)))
817816
->andWhere($qb->expr()->in('item_type', $qb->createNamedParameter(['file', 'folder'], IQueryBuilder::PARAM_STR_ARRAY)))
818-
->orderBy('id', 'ASC')
819817
->executeQuery();
820818

821819
$shares = [];
@@ -910,8 +908,10 @@ private function _getSharedWith(
910908
->leftJoin('s', 'filecache', 'f', $qb->expr()->eq('s.file_source', 'f.fileid'))
911909
->leftJoin('f', 'storages', 'st', $qb->expr()->eq('f.storage', 'st.numeric_id'));
912910

913-
// Order by id
914-
$qb->orderBy('s.id');
911+
if ($offset !== 0 || $limit !== -1) {
912+
// Order by id
913+
$qb->orderBy('s.id');
914+
}
915915

916916
// Set limit and offset
917917
if ($limit !== -1) {
@@ -980,9 +980,12 @@ private function _getSharedWith(
980980
->from('share', 's')
981981
->leftJoin('s', 'filecache', 'f', $qb->expr()->eq('s.file_source', 'f.fileid'))
982982
->leftJoin('f', 'storages', 'st', $qb->expr()->eq('f.storage', 'st.numeric_id'))
983-
->orderBy('s.id')
984983
->setFirstResult(0);
985984

985+
if ($offset !== 0 || $limit !== -1) {
986+
$qb->orderBy('s.id');
987+
}
988+
986989
if ($limit !== -1) {
987990
$qb->setMaxResults($limit - count($shares));
988991
}

tests/lib/Share20/DefaultShareProviderTest.php

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

664664
$children = $this->provider->getChildren($share);
665+
usort($children, fn (IShare $a, IShare $b) => $a->getId() <=> $b->getId());
665666

666667
$this->assertCount(2, $children);
667668

@@ -2642,6 +2643,7 @@ public function testGetSharesInFolder(): void {
26422643
$this->assertSame(IShare::TYPE_USER, $file_shares[0]->getShareType());
26432644

26442645
$folder_shares = $result[$folder2->getId()];
2646+
usort($folder_shares, fn (IShare $a, IShare $b) => $a->getId() <=> $b->getId());
26452647
$this->assertCount(2, $folder_shares);
26462648
$this->assertSame($folder2->getId(), $folder_shares[0]->getNodeId());
26472649
$this->assertSame($folder2->getId(), $folder_shares[1]->getNodeId());
@@ -3102,6 +3104,7 @@ public function testGetSharesByPath(): void {
31023104
->willReturn(1);
31033105

31043106
$shares = $this->provider->getSharesByPath($node);
3107+
usort($shares, fn (IShare $a, IShare $b) => $a->getId() <=> $b->getId());
31053108
$this->assertCount(3, $shares);
31063109

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

0 commit comments

Comments
 (0)