Skip to content

Commit

Permalink
Max file size for metadata generation
Browse files Browse the repository at this point in the history
Signed-off-by: Git'Fellow <12234510+solracsf@users.noreply.github.com>

enh(metadata): Introduce a memory limit for metadata generation

Signed-off-by: Git'Fellow <12234510+solracsf@users.noreply.github.com>

From Bytes to MiB

Signed-off-by: Git'Fellow <12234510+solracsf@users.noreply.github.com>

Fix psalm

Signed-off-by: Git'Fellow <12234510+solracsf@users.noreply.github.com>

Rename var to max_filesize

Signed-off-by: Git'Fellow <12234510+solracsf@users.noreply.github.com>
Co-Authored-By: Louis <louis@chmn.me>
  • Loading branch information
solracsf and artonge committed Jun 28, 2024
1 parent 32bf74a commit a88d4e0
Show file tree
Hide file tree
Showing 2 changed files with 21 additions and 0 deletions.
9 changes: 9 additions & 0 deletions config/config.sample.php
Original file line number Diff line number Diff line change
Expand Up @@ -1324,6 +1324,15 @@
'OC\Preview\XBitmap',
],

/**
* Maximum file size for metadata generation.
* If a file exceeds this size, metadata generation will be skipped.
* Note: memory equivalent to this size will be used for metadata generation.
*
* Default: 256 megabytes.
*/
'metadata_max_filesize' => 256,

/**
* LDAP
*
Expand Down
12 changes: 12 additions & 0 deletions core/BackgroundJobs/GenerateMetadataJob.php
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,9 @@
use Psr\Log\LoggerInterface;

class GenerateMetadataJob extends TimedJob {
// Default file size limit for metadata generation (MBytes).
protected const DEFAULT_MAX_FILESIZE = 256;

public function __construct(
ITimeFactory $time,
private IConfig $config,
Expand Down Expand Up @@ -100,6 +103,15 @@ private function scanFolder(Folder $folder): void {
continue;
}

// Don't generate metadata for files bigger than configured metadata_max_filesize
// Files are loaded in memory so very big files can lead to an OOM on the server
$nodeSize = $node->getSize();
$nodeLimit = $this->config->getSystemValueInt('metadata_max_filesize', self::DEFAULT_MAX_FILESIZE);
if ($nodeSize > $nodeLimit * 1000000) {
$this->logger->debug("Skipping generating metadata for fileid " . $node->getId() . " as its size exceeds configured 'metadata_max_filesize'.");
continue;
}

try {
$this->filesMetadataManager->getMetadata($node->getId(), false);
} catch (FilesMetadataNotFoundException) {
Expand Down

0 comments on commit a88d4e0

Please sign in to comment.