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

[TASK] Speed up the file processing queue with bulkInsert #8

Open
wants to merge 1 commit into
base: main
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
76 changes: 49 additions & 27 deletions Classes/Resource/ProcessedFileQueueRepository.php
Original file line number Diff line number Diff line change
Expand Up @@ -15,26 +15,23 @@
class ProcessedFileQueueRepository implements SingletonInterface
{
private const TABLE = 'sys_file_processedfile_queue';
private array $insertQueue = [];

public function __destruct()
{
$this->persistQueue();
}

public function enqueue(TaskInterface $task): void
{
$connection = GeneralUtility::makeInstance(ConnectionPool::class)->getConnectionForTable(self::TABLE);
$connection->insert(
self::TABLE,
[
'public_url' => $task->getTargetFile()->getPublicUrl(),
'storage' => $task->getSourceFile()->getStorage()->getUid(),
'original' => $task->getSourceFile()->getUid(),
'task_type' => $task->getType() . '.' . $task->getName(),
'configuration' => (new ConfigurationService())->serialize($task->getConfiguration()),
'checksum' => $task->getConfigurationChecksum()
],
[
'storage' => Connection::PARAM_INT,
'original' => Connection::PARAM_INT,
'configuration' => Connection::PARAM_LOB,
]
);
$this->insertQueue[$task->getConfigurationChecksum()] = [
'public_url' => $task->getTargetFile()->getPublicUrl(),
'storage' => $task->getSourceFile()->getStorage()->getUid(),
'original' => $task->getSourceFile()->getUid(),
'task_type' => $task->getType() . '.' . $task->getName(),
'configuration' => (new ConfigurationService())->serialize($task->getConfiguration()),
'checksum' => $task->getConfigurationChecksum()
];
}

public function dequeue(int $uid): void
Expand All @@ -49,16 +46,17 @@ public function dequeue(int $uid): void
public function isEnqueued(TaskInterface $task): bool
{
$connection = GeneralUtility::makeInstance(ConnectionPool::class)->getConnectionForTable(self::TABLE);
return (bool)$connection->count(
'*',
self::TABLE,
[
'storage' => $task->getSourceFile()->getStorage()->getUid(),
'original' => $task->getSourceFile()->getUid(),
'task_type' => $task->getType() . '.' . $task->getName(),
'checksum' => $task->getConfigurationChecksum()
],
);

return isset($this->insertQueue[$task->getConfigurationChecksum()]) || $connection->count(
'*',
self::TABLE,
[
'storage' => $task->getSourceFile()->getStorage()->getUid(),
'original' => $task->getSourceFile()->getUid(),
'task_type' => $task->getType() . '.' . $task->getName(),
'checksum' => $task->getConfigurationChecksum()
],
);
}

/**
Expand Down Expand Up @@ -89,4 +87,28 @@ public function findByPublicUrl(string $publicUrl): QueuedTask|bool
$result['checksum']
);
}

private function persistQueue(): void
{
if (count($this->insertQueue) > 0) {
$connection = GeneralUtility::makeInstance(ConnectionPool::class)->getConnectionForTable(self::TABLE);
$connection->bulkInsert(
self::TABLE,
$this->insertQueue,
[
'public_url',
'storage',
'original',
'task_type',
'configuration',
'checksum',
],
[
'storage' => Connection::PARAM_INT,
'original' => Connection::PARAM_INT,
'configuration' => Connection::PARAM_LOB,
]
);
}
}
}