Skip to content

Commit 2ac0221

Browse files
committed
perf: Port away from more getById
Replace by getFirstNodeById which is faster and also don't get the user folder multiple times inside a loop. Signed-off-by: Carl Schwan <carlschwan@kde.org>
1 parent 02eb3c7 commit 2ac0221

File tree

3 files changed

+16
-9
lines changed

3 files changed

+16
-9
lines changed

lib/Dav/Faces/FacePhoto.php

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -70,9 +70,8 @@ public function put($data): never {
7070

7171
public function getFile() : File {
7272
if ($this->file === null) {
73-
$nodes = $this->userFolder->getById($this->faceDetection->getFileId());
74-
$node = current($nodes);
75-
if ($node) {
73+
$node = $this->userFolder->getFirstNodeById($this->faceDetection->getFileId());
74+
if ($node !== null) {
7675
if ($node instanceof File) {
7776
return $this->file = $node;
7877
} else {

lib/Dav/Faces/FaceRoot.php

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -90,9 +90,10 @@ public function createFile($name, $data = null): never {
9090
public function getChildren(): array {
9191
if (count($this->children) === 0) {
9292
$detections = $this->detectionMapper->findByClusterId($this->cluster->getId());
93-
$detectionsWithFile = array_filter($detections, fn (FaceDetection $detection): bool => current($this->rootFolder->getUserFolder($this->user->getUID())->getById($detection->getFileId())) !== false);
94-
$this->children = array_map(function (FaceDetection $detection) {
95-
return new FacePhoto($this->detectionMapper, $detection, $this->rootFolder->getUserFolder($this->user->getUID()), $this->tagManager, $this->previewManager);
93+
$userFolder = $this->rootFolder->getUserFolder($this->user->getUID());
94+
$detectionsWithFile = array_filter($detections, fn (FaceDetection $detection): bool => $userFolder->getFirstNodeById($detection->getFileId()) !== null);
95+
$this->children = array_map(function (FaceDetection $detection) use ($userFolder) {
96+
return new FacePhoto($this->detectionMapper, $detection, $userFolder, $this->tagManager, $this->previewManager);
9697
}, $detectionsWithFile);
9798
}
9899
return $this->children;

lib/Dav/Faces/UnassignedFacesHome.php

Lines changed: 10 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -102,10 +102,17 @@ public function getChildren(): array {
102102
}
103103

104104
$detections = $this->faceDetectionMapper->findRejectedByUserId($this->user->getUID());
105-
$detectionsWithFile = array_filter($detections, fn (FaceDetection $detection): bool => current($this->rootFolder->getUserFolder($this->user->getUID())->getById($detection->getFileId())) !== false);
105+
$userFolder = $this->rootFolder->getUserFolder($this->user->getUID());
106+
$detectionsWithFile = array_filter($detections, fn (FaceDetection $detection): bool =>
107+
$userFolder->getFirstNodeById($detection->getFileId()) !== null);
106108
$this->children = array_values(array_map(fn (FaceDetection $detection): UnassignedFacePhoto
107-
=> new UnassignedFacePhoto($this->faceDetectionMapper, $detection, $this->rootFolder->getUserFolder($this->user->getUID()), $this->tagManager, $this->previewManager),
108-
$detectionsWithFile));
109+
=> new UnassignedFacePhoto(
110+
$this->faceDetectionMapper,
111+
$detection,
112+
$this->rootFolder->getUserFolder($this->user->getUID()),
113+
$this->tagManager,
114+
$this->previewManager
115+
), $detectionsWithFile));
109116

110117
return $this->children;
111118
}

0 commit comments

Comments
 (0)