Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[stable28] Request background job to generate metadata on non-local files #2245

Merged
merged 1 commit into from Jan 9, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
3 changes: 3 additions & 0 deletions lib/AppInfo/Application.php
Expand Up @@ -91,8 +91,11 @@ public function register(IRegistrationContext $context): void {

// Metadata
$context->registerEventListener(MetadataLiveEvent::class, ExifMetadataProvider::class);
$context->registerEventListener(MetadataBackgroundEvent::class, ExifMetadataProvider::class);
$context->registerEventListener(MetadataLiveEvent::class, SizeMetadataProvider::class);
$context->registerEventListener(MetadataBackgroundEvent::class, SizeMetadataProvider::class);
$context->registerEventListener(MetadataLiveEvent::class, OriginalDateTimeMetadataProvider::class);
$context->registerEventListener(MetadataBackgroundEvent::class, OriginalDateTimeMetadataProvider::class);
$context->registerEventListener(MetadataLiveEvent::class, PlaceMetadataProvider::class);
$context->registerEventListener(MetadataBackgroundEvent::class, PlaceMetadataProvider::class);

Expand Down
10 changes: 9 additions & 1 deletion lib/Listener/ExifMetadataProvider.php
Expand Up @@ -26,6 +26,7 @@
use OCP\EventDispatcher\Event;
use OCP\EventDispatcher\IEventListener;
use OCP\Files\File;
use OCP\FilesMetadata\Event\MetadataBackgroundEvent;
use OCP\FilesMetadata\Event\MetadataLiveEvent;
use Psr\Log\LoggerInterface;

Expand All @@ -42,7 +43,7 @@ public function __construct(
}

public function handle(Event $event): void {
if (!($event instanceof MetadataLiveEvent)) {
if (!($event instanceof MetadataLiveEvent) && !($event instanceof MetadataBackgroundEvent)) {
return;
}

Expand All @@ -52,6 +53,13 @@ public function handle(Event $event): void {
return;
}

// We need the file content to extract the EXIF data.
// This can be slow for remote storage, so we do it in a background job.
if (!$node->getStorage()->isLocal() && $event instanceof MetadataLiveEvent) {
$event->requestBackgroundJob();
return;
}

if (!in_array($node->getMimeType(), Application::IMAGE_MIMES)) {
return;
}
Expand Down
10 changes: 9 additions & 1 deletion lib/Listener/OriginalDateTimeMetadataProvider.php
Expand Up @@ -27,6 +27,7 @@
use OCP\EventDispatcher\Event;
use OCP\EventDispatcher\IEventListener;
use OCP\Files\File;
use OCP\FilesMetadata\Event\MetadataBackgroundEvent;
use OCP\FilesMetadata\Event\MetadataLiveEvent;
use Psr\Log\LoggerInterface;

Expand Down Expand Up @@ -68,7 +69,7 @@ private function dateToTimestamp(string $format, string $date, File $node): int|
}

public function handle(Event $event): void {
if (!($event instanceof MetadataLiveEvent)) {
if (!($event instanceof MetadataLiveEvent) && !($event instanceof MetadataBackgroundEvent)) {
return;
}

Expand All @@ -78,6 +79,13 @@ public function handle(Event $event): void {
return;
}

// We need the file content to extract the EXIF data.
// This can be slow for remote storage, so we do it in a background job.
if (!$node->getStorage()->isLocal() && $event instanceof MetadataLiveEvent) {
$event->requestBackgroundJob();
return;
}

if (!in_array($node->getMimeType(), Application::IMAGE_MIMES) && !in_array($node->getMimeType(), Application::VIDEO_MIMES)) {
return;
}
Expand Down
10 changes: 9 additions & 1 deletion lib/Listener/SizeMetadataProvider.php
Expand Up @@ -26,6 +26,7 @@
use OCP\EventDispatcher\Event;
use OCP\EventDispatcher\IEventListener;
use OCP\Files\File;
use OCP\FilesMetadata\Event\MetadataBackgroundEvent;
use OCP\FilesMetadata\Event\MetadataLiveEvent;
use Psr\Log\LoggerInterface;

Expand All @@ -39,7 +40,7 @@ public function __construct(
}

public function handle(Event $event): void {
if (!($event instanceof MetadataLiveEvent)) {
if (!($event instanceof MetadataLiveEvent) && !($event instanceof MetadataBackgroundEvent)) {
return;
}

Expand All @@ -49,6 +50,13 @@ public function handle(Event $event): void {
return;
}

// We need the file content to extract the size.
// This can be slow for remote storage, so we do it in a background job.
if (!$node->getStorage()->isLocal() && $event instanceof MetadataLiveEvent) {
$event->requestBackgroundJob();
return;
}

if (!in_array($node->getMimeType(), Application::IMAGE_MIMES)) {
return;
}
Expand Down