-
Notifications
You must be signed in to change notification settings - Fork 6
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Move Resaving completely into queue + 10k batching.
- Loading branch information
1 parent
5fcab74
commit d072254
Showing
5 changed files
with
69 additions
and
40 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,47 @@ | ||
<?php | ||
|
||
namespace internetztube\elementRelations\jobs; | ||
|
||
use Craft; | ||
use craft\db\Query; | ||
use craft\db\Table; | ||
use craft\helpers\Db; | ||
use craft\queue\BaseJob; | ||
|
||
/** | ||
* Resave Element Relations Job queue job | ||
*/ | ||
class GenerateResaveAllElementRelationsJobsJob extends BaseJob | ||
{ | ||
function execute($queue): void | ||
{ | ||
$query = (new Query()) | ||
->select([ | ||
'elements_sites.elementId', | ||
'elements_sites.siteId', | ||
'elements.type' | ||
]) | ||
->from(['elements_sites' => Table::ELEMENTS_SITES]) | ||
->innerJoin(['elements' => Table::ELEMENTS], "[[elements.id]] = [[elements_sites.elementId]]") | ||
->where(['is', 'elements.dateDeleted', null]); | ||
|
||
$batchSize = 10000; | ||
$totalCount = $query->count(); | ||
$totalBatches = ceil($totalCount / $batchSize); | ||
$index = 0; | ||
|
||
foreach (Db::batch($query, $batchSize) as $batch) { | ||
$index += 1; | ||
$job = new ResaveAllElementRelationsJob([ | ||
'batch' => $batch, | ||
'description' => "Resave All Element Relations ($index/$totalBatches)" | ||
]); | ||
Craft::$app->getQueue()->push($job); | ||
$this->setProgress($queue, $index / $totalBatches, "$index/$totalBatches"); | ||
} | ||
} | ||
protected function defaultDescription(): ?string | ||
{ | ||
return "Generate Resave All Element Relations Jobs"; | ||
} | ||
} |
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