Skip to content

Commit a29e01f

Browse files
authored
Merge pull request #1450 from nextcloud/backport/1449/stable11
fix: Migrate `getById` to `getFirstNodeById`
2 parents d2f7b97 + e5865b8 commit a29e01f

File tree

2 files changed

+11
-11
lines changed

2 files changed

+11
-11
lines changed

lib/Classifiers/Classifier.php

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -79,8 +79,8 @@ public function classifyFiles(string $model, array $queueFiles, int $timeout): \
7979
if ($this->maxExecutionTime > 0 && time() - $startTime > $this->maxExecutionTime) {
8080
return;
8181
}
82-
$files = $this->rootFolder->getById($queueFile->getFileId());
83-
if (count($files) === 0) {
82+
$file = $this->rootFolder->getFirstNodeById($queueFile->getFileId());
83+
if ($file === null) {
8484
try {
8585
$this->logger->debug('removing '.$queueFile->getFileId().' from '.$model.' queue because it couldn\'t be found');
8686
$this->queue->removeFromQueue($model, $queueFile);
@@ -90,8 +90,8 @@ public function classifyFiles(string $model, array $queueFiles, int $timeout): \
9090
continue;
9191
}
9292
try {
93-
if ($files[0]->getSize() == 0) {
94-
$this->logger->debug('File is empty: ' . $files[0]->getPath());
93+
if ($file->getSize() == 0) {
94+
$this->logger->debug('File is empty: ' . $file->getPath());
9595
try {
9696
$this->logger->debug('removing ' . $queueFile->getFileId() . ' from ' . $model . ' queue');
9797
$this->queue->removeFromQueue($model, $queueFile);
@@ -100,14 +100,14 @@ public function classifyFiles(string $model, array $queueFiles, int $timeout): \
100100
}
101101
continue;
102102
}
103-
$path = $this->getConvertedFilePath($files[0]);
103+
$path = $this->getConvertedFilePath($file);
104104
if (in_array($model, [ImagenetClassifier::MODEL_NAME, LandmarksClassifier::MODEL_NAME, ClusteringFaceClassifier::MODEL_NAME], true)) {
105105
// Check file data size
106106
$filesize = filesize($path);
107107
if ($filesize !== false) {
108108
$filesizeMb = $filesize / (1024 * 1024);
109109
if ($filesizeMb > 8) {
110-
$this->logger->debug('File is too large for classifier: ' . $files[0]->getPath());
110+
$this->logger->debug('File is too large for classifier: ' . $file->getPath());
111111
try {
112112
$this->logger->debug('removing ' . $queueFile->getFileId() . ' from ' . $model . ' queue');
113113
$this->queue->removeFromQueue($model, $queueFile);
@@ -120,7 +120,7 @@ public function classifyFiles(string $model, array $queueFiles, int $timeout): \
120120
// Check file dimensions
121121
$dimensions = @getimagesize($path);
122122
if (isset($dimensions) && $dimensions !== false && ($dimensions[0] > 1024 || $dimensions[1] > 1024)) {
123-
$this->logger->debug('File dimensions are too large for classifier: ' . $files[0]->getPath());
123+
$this->logger->debug('File dimensions are too large for classifier: ' . $file->getPath());
124124
try {
125125
$this->logger->debug('removing ' . $queueFile->getFileId() . ' from ' . $model . ' queue');
126126
$this->queue->removeFromQueue($model, $queueFile);
@@ -132,7 +132,7 @@ public function classifyFiles(string $model, array $queueFiles, int $timeout): \
132132
}
133133
$paths[] = $path;
134134
$processedFiles[] = $queueFile;
135-
$fileNames[] = $files[0]->getPath();
135+
$fileNames[] = $file->getPath();
136136
} catch (NotFoundException|InvalidPathException $e) {
137137
$this->logger->warning('Could not find file', ['exception' => $e]);
138138
try {

lib/Hooks/FileListener.php

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -265,7 +265,7 @@ public function handle(Event $event): void {
265265
return;
266266
}
267267
if ($event instanceof CacheEntryInsertedEvent) {
268-
$node = current($this->rootFolder->getById($event->getFileId()));
268+
$node = $this->rootFolder->getFirstNodeById($event->getFileId());
269269
if ($node === false) {
270270
return;
271271
}
@@ -284,7 +284,7 @@ public function handle(Event $event): void {
284284
if ($cacheEntry === false) {
285285
return;
286286
}
287-
$node = current($this->rootFolder->getById($cacheEntry->getId()));
287+
$node = $this->rootFolder->getFirstNodeById($cacheEntry->getId());
288288
if ($node === false) {
289289
return;
290290
}
@@ -546,7 +546,7 @@ private function onAccessUpdate(int $storageId, int $rootId): void {
546546
$files = $this->storageService->getFilesInMount($storageId, $rootId, [ClusteringFaceClassifier::MODEL_NAME], 0, 0);
547547
$userIdsToScheduleClustering = [];
548548
foreach ($files as $fileInfo) {
549-
$node = current($this->rootFolder->getById($fileInfo['fileid'])) ?: null;
549+
$node = $this->rootFolder->getFirstNodeById($fileInfo['fileid']) ?: null;
550550
$ownerId = $node?->getOwner()?->getUID();
551551
if ($ownerId === null) {
552552
continue;

0 commit comments

Comments
 (0)