Skip to content

Commit

Permalink
getBatchSize
Browse files Browse the repository at this point in the history
  • Loading branch information
fogelito committed Aug 6, 2024
1 parent 8ccde49 commit de4c092
Show file tree
Hide file tree
Showing 6 changed files with 15 additions and 23 deletions.
3 changes: 0 additions & 3 deletions src/Migration/Destination.php
Original file line number Diff line number Diff line change
Expand Up @@ -27,21 +27,18 @@ public function setSource(Source $source): self
* @param array<string> $resources Resources to transfer
* @param callable $callback Callback to run after transfer
* @param string $rootResourceId Root resource ID, If enabled you can only transfer a single root resource
* @param int $batchSize The number of resources to transfer in a single batch
*/
public function run(
array $resources,
callable $callback,
string $rootResourceId = '',
int $batchSize = 100,
): void {
$this->source->run(
$resources,
function (array $resources) use ($callback) {
$this->import($resources, $callback);
},
$rootResourceId,
$batchSize
);
}

Expand Down
5 changes: 0 additions & 5 deletions src/Migration/Destinations/Appwrite.php
Original file line number Diff line number Diff line change
Expand Up @@ -1340,9 +1340,4 @@ private function importDeployment(Deployment $deployment): Resource

return $deployment;
}

public function getBatchSize(): int
{
return 200;
}
}
15 changes: 9 additions & 6 deletions src/Migration/Source.php
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ public function callback(array $resources): void
* @param callable $callback Callback to run after transfer
* @param string $rootResourceId Root resource ID, If enabled you can only transfer a single root resource
*/
public function run(array $resources, callable $callback, string $rootResourceId = '', int $batchSize = 100): void
public function run(array $resources, callable $callback, string $rootResourceId = ''): void
{
$this->rootResourceId = $rootResourceId;

Expand All @@ -46,21 +46,20 @@ public function run(array $resources, callable $callback, string $rootResourceId
$this->cache->addAll($prunedResources);
};

$batchSize = $this->getBatchSize();

$this->exportResources($resources, $batchSize);
$this->exportResources($resources);
}

/**
* Export Resources
*
* @param array<string> $resources Resources to export
* @param int $batchSize Max 100
*/
public function exportResources(array $resources, int $batchSize): void
public function exportResources(array $resources): void
{
// Convert Resources back into their relevant groups

$batchSize = $this->getBatchSize();

$groups = [];
foreach ($resources as $resource) {
if (\in_array($resource, Transfer::GROUP_AUTH_RESOURCES)) {
Expand Down Expand Up @@ -96,6 +95,10 @@ public function exportResources(array $resources, int $batchSize): void
}
}
}
public function getBatchSize(): int
{
return 100;
}

/**
* Export Auth Group
Expand Down
7 changes: 6 additions & 1 deletion src/Migration/Sources/Appwrite.php
Original file line number Diff line number Diff line change
Expand Up @@ -1468,4 +1468,9 @@ private function exportDeploymentData(Func $func, array $deployment): void
}
}
}
}

public function getBatchSize(): int
{
return 250;
}
}
5 changes: 0 additions & 5 deletions src/Migration/Target.php
Original file line number Diff line number Diff line change
Expand Up @@ -225,9 +225,4 @@ public function addWarning(Warning $warning): void
public function shutdown(): void
{
}

public function getBatchSize(): int
{
return 100;
}
}
3 changes: 0 additions & 3 deletions src/Migration/Transfer.php
Original file line number Diff line number Diff line change
Expand Up @@ -181,14 +181,12 @@ public function getStatusCounters(): array
* @param array<string> $resources Resources to transfer
* @param callable $callback Callback to run after transfer
* @param string|null $rootResourceId Root resource ID, If enabled you can only transfer a single root resource
* @param int $batchSize
* @throws \Exception
*/
public function run(
array $resources,
callable $callback,
string $rootResourceId = null,
int $batchSize = 100
): void {
// Allows you to push entire groups if you want.
$computedResources = [];
Expand Down Expand Up @@ -217,7 +215,6 @@ public function run(
$computedResources,
$callback,
$rootResourceId,
$batchSize
);
}

Expand Down

0 comments on commit de4c092

Please sign in to comment.