-
Notifications
You must be signed in to change notification settings - Fork 25
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add batching to import and sync queue jobs
- Loading branch information
Showing
10 changed files
with
257 additions
and
138 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,33 @@ | ||
<?php | ||
|
||
namespace putyourlightson\campaign\batchers; | ||
|
||
use craft\base\Batchable; | ||
|
||
/** | ||
* @since 2.13.0 | ||
*/ | ||
class PendingRecipientBatcher implements Batchable | ||
{ | ||
public function __construct( | ||
private array $pendingRecipients, | ||
private ?int $limit = null, | ||
) { | ||
} | ||
|
||
/** | ||
* @inheritdoc | ||
*/ | ||
public function count(): int | ||
{ | ||
return min(count($this->pendingRecipients), $this->limit ?? 0); | ||
} | ||
|
||
/** | ||
* Returns a batch of pending recipients, using the limit and ignoring the offset, since the pending recipients array is calculated fresh each time. | ||
*/ | ||
public function getSlice(int $offset, int $limit): iterable | ||
{ | ||
return array_slice($this->pendingRecipients, 0, $limit); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,32 @@ | ||
<?php | ||
|
||
namespace putyourlightson\campaign\batchers; | ||
|
||
use craft\base\Batchable; | ||
|
||
/** | ||
* @since 2.13.0 | ||
*/ | ||
class RowBatcher implements Batchable | ||
{ | ||
public function __construct( | ||
private array $rows, | ||
) { | ||
} | ||
|
||
/** | ||
* @inheritdoc | ||
*/ | ||
public function count(): int | ||
{ | ||
return count($this->rows); | ||
} | ||
|
||
/** | ||
* @inheritdoc | ||
*/ | ||
public function getSlice(int $offset, int $limit): iterable | ||
{ | ||
return array_slice($this->rows, $offset, $limit); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.