-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
chore(SLB-261): high volume content test
- Loading branch information
Showing
4 changed files
with
170 additions
and
0 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,50 @@ | ||
name: High Content Volume | ||
on: | ||
workflow_dispatch: | ||
|
||
jobs: | ||
test: | ||
name: Test | ||
runs-on: ubuntu-latest | ||
steps: | ||
- name: Checkout | ||
uses: actions/checkout@v3 | ||
with: | ||
fetch-depth: 1 | ||
|
||
- name: Setup | ||
uses: ./.github/actions/setup | ||
|
||
- name: TurboRepo local server | ||
uses: felixmosh/turborepo-gh-artifacts@v2 | ||
with: | ||
server-token: 'local' | ||
repo-token: ${{ secrets.GITHUB_TOKEN }} | ||
|
||
- name: Prepare | ||
run: pnpm turbo:prep | ||
env: | ||
TURBO_API: 'http://127.0.0.1:9080' | ||
TURBO_TOKEN: 'local' | ||
TURBO_TEAM: 'local' | ||
|
||
- name: 'Drupal: Start' | ||
run: pnpm --filter "@custom/cms" drush start & | ||
|
||
- name: 'Gatsby: Clean' | ||
run: pnpm --filter "@custom/website" gatsby clean | ||
|
||
- name: 'Drupal: Create content' | ||
run: pnpm --filter "@custom/cms" drush php:script scripts/create-lots-of-content/run.php | ||
|
||
- name: 'Gatsby: Full build' | ||
run: pnpm --filter "@custom/website" gatsby build | ||
|
||
- name: 'Gatsby: Incremental build without new content' | ||
run: pnpm --filter "@custom/website" gatsby build | ||
|
||
- name: 'Drupal: Create more content' | ||
run: pnpm --filter "@custom/cms" drush php:script scripts/create-lots-of-content/create-100-pages.php | ||
|
||
- name: 'Gatsby: Incremental build with new content' | ||
run: pnpm --filter "@custom/website" gatsby build |
99 changes: 99 additions & 0 deletions
99
apps/cms/scripts/create-lots-of-content/create-100-pages.php
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,99 @@ | ||
<?php | ||
|
||
use Drupal\Component\Utility\Random; | ||
use Drupal\media\Entity\Media; | ||
use Drupal\node\Entity\Node; | ||
|
||
|
||
/** @var \Drupal\file\FileRepositoryInterface $fileRepository */ | ||
$fileRepository = \Drupal::service('file.repository'); | ||
$random = new Random(); | ||
|
||
$imageData = file_get_contents(__DIR__ . '/tiny.png'); | ||
|
||
for ($pageIndex = 1; $pageIndex <= 100; $pageIndex++) { | ||
|
||
// Prepare images. | ||
/** @var \Drupal\file\FileInterface[] $images */ | ||
$images = []; | ||
for ($i = 1; $i <= 4; $i++) { | ||
$images[$i] = $fileRepository->writeData($imageData, "public://" . $random->machineName(32) . ".png"); | ||
} | ||
|
||
// Prepare image media entities. | ||
/** @var \Drupal\media\MediaInterface[] $media */ | ||
$media = []; | ||
foreach ($images as $i => $image) { | ||
$media[$i] = Media::create([ | ||
'name' => $random->name(), | ||
'bundle' => 'image', | ||
'uid' => 1, | ||
'status' => TRUE, | ||
'field_media_image' => [ | ||
'target_id' => $image->id(), | ||
'alt' => 'Alt text', | ||
'title' => 'Title text', | ||
], | ||
]); | ||
$media[$i]->save(); | ||
} | ||
$mediaIds = array_map(fn ($media) => $media->id(), $media); | ||
|
||
// Create a page. | ||
$title = $random->name(); | ||
$node = Node::create([ | ||
'type' => 'page', | ||
'status' => TRUE, | ||
'uid' => 1, | ||
'title' => $title, | ||
'moderation_state' => 'published', | ||
'body' => [ | ||
'value' => pageBody($mediaIds, FALSE), | ||
'format' => 'gutenberg', | ||
'summary' => '', | ||
], | ||
]); | ||
$node->addTranslation('de', [ | ||
'title' => $title . ' DE', | ||
'uid' => 1, | ||
'body' => [ | ||
'value' => pageBody($mediaIds, TRUE), | ||
'format' => 'gutenberg', | ||
'summary' => '', | ||
], | ||
]); | ||
$node->save(); | ||
} | ||
|
||
function pageBody(array $mediaIds, bool $isGerman): string { | ||
$suffix = $isGerman ? ' DE' : ''; | ||
return <<<EOT | ||
<!-- wp:custom/hero {"mediaEntityIds":["$mediaIds[1]"],"headline":"Stub page$suffix","lead":"Lead text$suffix"} /--> | ||
<!-- wp:custom/content --> | ||
<!-- wp:paragraph --> | ||
<p>Some content$suffix</p> | ||
<!-- /wp:paragraph --> | ||
<!-- wp:drupalmedia/drupal-media-entity {"mediaEntityIds":["$mediaIds[2]"],"caption":"Caption$suffix"} /--> | ||
<!-- wp:paragraph --> | ||
<p>Some content$suffix</p> | ||
<!-- /wp:paragraph --> | ||
<!-- wp:drupalmedia/drupal-media-entity {"mediaEntityIds":["$mediaIds[3]"],"caption":"Caption$suffix"} /--> | ||
<!-- wp:paragraph --> | ||
<p><meta charset="utf-8">Some content$suffix</p> | ||
<!-- /wp:paragraph --> | ||
<!-- wp:drupalmedia/drupal-media-entity {"mediaEntityIds":["$mediaIds[4]"],"caption":"Caption$suffix"} /--> | ||
<!-- wp:paragraph --> | ||
<p></p> | ||
<!-- /wp:paragraph --> | ||
<!-- /wp:custom/content --> | ||
EOT; | ||
} | ||
|
||
|
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,21 @@ | ||
<?php | ||
|
||
$amount = 200; | ||
$total = $amount * 100; | ||
|
||
echo "Gonna create $total pages.\n"; | ||
|
||
for ($i = 1; $i <= $amount; $i++) { | ||
|
||
// The more pages we create in a single run, the slower Drupal works and the | ||
// more memory is eaten by PHP. So we create pages in batches. | ||
exec('../vendor/bin/drush php:script ' . __DIR__ . '/create-100-pages.php'); | ||
|
||
if ($i !== 1) { | ||
echo "\r"; | ||
} | ||
$percent = number_format(100 * $i / $amount, 2); | ||
echo "Progress $percent%"; | ||
} | ||
|
||
echo "\nDone!\n"; |
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.