Skip to content

Commit c17d67c

Browse files
committed
fix(QueueMapper): Add ORDER BY clause to getFromQueue for DBs like postgres
Signed-off-by: Marcel Klehr <mklehr@gmx.net>
1 parent 1869f78 commit c17d67c

File tree

1 file changed

+4
-3
lines changed

1 file changed

+4
-3
lines changed

lib/Db/QueueMapper.php

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -42,7 +42,8 @@ public function getFromQueue(int $storageId, int $rootId, int $n) : array {
4242
->from($this->getTableName())
4343
->where($qb->expr()->eq('storage_id', $qb->createPositionalParameter($storageId, IQueryBuilder::PARAM_INT)))
4444
->andWhere($qb->expr()->eq('root_id', $qb->createPositionalParameter($rootId, IQueryBuilder::PARAM_INT)))
45-
->setMaxResults($n);
45+
->setMaxResults($n)
46+
->orderBy('id', 'ASC');
4647

4748
return $this->findEntities($qb);
4849
}
@@ -53,9 +54,9 @@ public function getFromQueue(int $storageId, int $rootId, int $n) : array {
5354
* @throws \OCP\DB\Exception
5455
*/
5556
public function removeFromQueue(array $files): void {
56-
$fileIds = array_map(fn (QueueFile $file) => $file->getId(), $files);
57+
$ids = array_map(fn (QueueFile $file) => $file->getId(), $files);
5758
$chunkSize = 1000; // Maximum number of items in an "IN" expression
58-
foreach (array_chunk($fileIds, $chunkSize) as $chunk) {
59+
foreach (array_chunk($ids, $chunkSize) as $chunk) {
5960
$qb = $this->db->getQueryBuilder();
6061
$qb->delete($this->getTableName())
6162
->where($qb->expr()->in('id', $qb->createPositionalParameter($chunk, IQueryBuilder::PARAM_INT_ARRAY)))

0 commit comments

Comments
 (0)