Skip to content

Commit

Permalink
Fix fetch of resources in refresh stored resources command
Browse files Browse the repository at this point in the history
  • Loading branch information
RandyCupic committed Oct 15, 2023
1 parent 2b1b825 commit 9710f84
Showing 1 changed file with 16 additions and 9 deletions.
25 changes: 16 additions & 9 deletions bundle/Command/RefreshStoredResourcesCommand.php
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,8 @@ final class RefreshStoredResourcesCommand extends Command

private ProgressBar $progressBar;

private int $batchSize = 500;

/** @var \Netgen\RemoteMedia\API\Values\RemoteResource[] */
private array $resourcesToDelete;

Expand All @@ -50,7 +52,7 @@ protected function configure(): void

protected function execute(InputInterface $input, OutputInterface $output): int
{
$limit = $input->getOption('batch-size');
$this->batchSize = $input->getOption('batch-size');
$delete = $input->getOption('delete');
$offset = 0;

Expand All @@ -60,11 +62,11 @@ protected function execute(InputInterface $input, OutputInterface $output): int
$this->resourcesToDelete = [];

do {
$resources = $this->getBatch($limit, $offset);
$resources = $this->getBatch($this->batchSize, $offset);

$this->refreshResources($resources);

$offset += $limit;
$offset += $this->batchSize;
} while (count($resources) > 0);

$this->progressBar->finish();
Expand Down Expand Up @@ -135,14 +137,19 @@ private function refreshResources(array $resources): void
*/
private function getRemoteBatch(array $remoteIds): array
{
$query = Query::fromRemoteIds($remoteIds);

$searchResult = $this->provider->search($query);
$query = Query::fromRemoteIds($remoteIds, $this->batchSize);

$resources = [];
foreach ($searchResult->getResources() as $resource) {
$resources[$resource->getRemoteId()] = $resource;
}

do {
$searchResult = $this->provider->search($query);

foreach ($searchResult->getResources() as $resource) {
$resources[$resource->getRemoteId()] = $resource;
}

$query->setNextCursor($searchResult->getNextCursor());
} while($searchResult->getNextCursor() !== null);

return $resources;
}
Expand Down

0 comments on commit 9710f84

Please sign in to comment.