Question about FilesMetadata code in Nextcloud 34.0.4

The Basics

Nextcloud Server version:

34.0.4.1

Operating system and version:

Ubuntu 22.04.5 LTS

Web server and version:

Nginx

Reverse proxy and version:

None

PHP version:

8.3

Database:

PostgreSQL

Is this the first time you’ve seen this error?

No

When did this problem seem to first start?

While investigating metadata cleanup and background jobs in Nextcloud 34.0.4.

Installation method:

Bare Metal

Are you using Cloudflare, mod_security, or similar?

No

Summary of the issue you are facing

Hello,

While investigating metadata-related background jobs, I noticed what appears to be a possible inconsistency in the Nextcloud source code and I would like clarification from the community or developers.

File:

lib/private/FilesMetadata/Service/MetadataRequestService.php

Method:

dropMetadataForFiles()

The code creates chunks of 1000 file IDs:


$chunks = array_chunk($fileIds, 1000);

foreach ($chunks as $chunk) {

 ...

}

However, inside the foreach loop the DELETE query appears to use the original `$fileIds` array instead of the current `$chunk`:


$qb->createNamedParameter(

 $fileIds,

 IQueryBuilder::PARAM_INT_ARRAY

);

I am wondering whether the code was intended to use:


$qb->createNamedParameter(

 $chunk,

 IQueryBuilder::PARAM_INT_ARRAY

);

On my server, the actual code currently looks like this:


public function dropMetadataForFiles(int $storage, array $fileIds): void {

 $chunks = array_chunk($fileIds, 1000);

 foreach ($chunks as $chunk) {

 $qb = $this->dbConnection->getQueryBuilder();

 $qb->delete(self::TABLE_METADATA)

 ->where($qb->expr()->in(

 'file_id',

 $qb->createNamedParameter(

 $fileIds,

 IQueryBuilder::PARAM_INT_ARRAY

 )

 ))

 ->hintShardKey('storage', $storage);

 $qb->executeStatement();

 }

}

While investigating this behavior, I also checked the current status of the system:

  • Cron is running correctly every 5 minutes.

  • Files_Trashbin background jobs are executing successfully.

  • Trash cleanup is working correctly.

  • Metadata jobs are being created and processed.

  • The server is currently operating normally.

  • Nextcloud version is 34.0.4.1.

  • The installation uses PostgreSQL, Nginx and PHP 8.3 on Ubuntu 22.04.5 LTS.

I am not proposing a fix and the server is currently operating normally.

I only want to understand whether this behavior is intentional or whether `$chunk` was intended to be used inside the foreach loop.

Steps to replicate it

  1. Open `lib/private/FilesMetadata/Service/MetadataRequestService.php`

  2. Locate the method `dropMetadataForFiles()`

  3. Review the `array_chunk()` implementation

  4. Observe that the foreach loop iterates through $chunk

  5. Observe that createNamedParameter() uses $fileIds

Question

Can someone confirm whether using $fileIds inside the foreach loop is expected behavior, or whether $chunk was intended here?

Thank you.