Skip to content

Optimize waitForAllTasks() to filter only pending tasks #421

@coderabbitai

Description

@coderabbitai

Description

The current implementation of waitForAllTasks() in tests/BaseKernelTestCase.php iterates over all tasks returned by getTasks(), including completed historical tasks. This can lead to unnecessary iterations in test environments with large task queues.

Current Implementation

protected function waitForAllTasks(): void
{
    foreach ($this->client->getTasks() as $task) {
        $this->client->waitForTask($task['uid']);
    }
}

Proposed Solution

Use the TasksQuery class from meilisearch-php to filter only tasks with enqueued or processing statuses:

use Meilisearch\Contracts\TasksQuery;

protected function waitForAllTasks(): void
{
    $query = (new TasksQuery())->setStatuses(['enqueued', 'processing']);
    foreach ($this->client->getTasks($query) as $task) {
        $this->client->waitForTask($task['uid']);
    }
}

This approach:

  • Reduces iteration over completed tasks
  • Improves performance in test environments with large task histories
  • Uses the official meilisearch-php TasksQuery API

References

Metadata

Metadata

Assignees

Labels

No labels
No labels

Type

No type

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions