Skip to content

Commit

Permalink
Parameterise batch size
Browse files Browse the repository at this point in the history
  • Loading branch information
abnegate committed Aug 5, 2024
1 parent 2f54112 commit 6644708
Show file tree
Hide file tree
Showing 5 changed files with 32 additions and 13 deletions.
20 changes: 15 additions & 5 deletions src/Migration/Destination.php
Original file line number Diff line number Diff line change
Expand Up @@ -27,12 +27,22 @@ 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 = ''): void
{
$this->source->run($resources, function (array $resources) use ($callback) {
$this->import($resources, $callback);
}, $rootResourceId);
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
1 change: 0 additions & 1 deletion src/Migration/Resources/Database/Attributes/Email.php
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@

namespace Utopia\Migration\Resources\Database\Attributes;

use Utopia\Database\Database;
use Utopia\Migration\Resources\Database\Attribute;
use Utopia\Migration\Resources\Database\Collection;

Expand Down
4 changes: 2 additions & 2 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 = ''): void
public function run(array $resources, callable $callback, string $rootResourceId = '', int $batchSize = 100): void
{
$this->rootResourceId = $rootResourceId;

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

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

/**
Expand Down
2 changes: 1 addition & 1 deletion src/Migration/Sources/Appwrite.php
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@
use Appwrite\Services\Storage;
use Appwrite\Services\Teams;
use Appwrite\Services\Users;
use Utopia\Database\Database as UtopiaDatabase;
use Utopia\Migration\Exception;
use Utopia\Migration\Resource;
use Utopia\Migration\Resources\Auth\Hash;
Expand Down Expand Up @@ -38,7 +39,6 @@
use Utopia\Migration\Resources\Storage\File;
use Utopia\Migration\Source;
use Utopia\Migration\Transfer;
use Utopia\Database\Database as UtopiaDatabase;

class Appwrite extends Source
{
Expand Down
18 changes: 14 additions & 4 deletions src/Migration/Transfer.php
Original file line number Diff line number Diff line change
Expand Up @@ -180,12 +180,16 @@ 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 string $rootResourceId Root resource ID, If enabled you can only transfer a single root resource
*
* @throws \Exception
*/
public function run(array $resources, callable $callback, string $rootResourceId = null): void
{
public function run(
array $resources,
callable $callback,
string $rootResourceId = '',
int $batchSize = 100
): void {
// Allows you to push entire groups if you want.
$computedResources = [];
foreach ($resources as $resource) {
Expand All @@ -208,7 +212,13 @@ public function run(array $resources, callable $callback, string $rootResourceId
}

$this->resources = $computedResources;
$this->destination->run($computedResources, $callback, $rootResourceId);

$this->destination->run(
$computedResources,
$callback,
$rootResourceId,
$batchSize
);
}

/**
Expand Down

0 comments on commit 6644708

Please sign in to comment.