Skip to content

Commit

Permalink
chore(SLB-261): high volume content test
Browse files Browse the repository at this point in the history
  • Loading branch information
Leksat committed Mar 7, 2024
1 parent 0996d95 commit 117a5a5
Show file tree
Hide file tree
Showing 4 changed files with 170 additions and 0 deletions.
50 changes: 50 additions & 0 deletions .github/workflows/high_content_volume.yml
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 apps/cms/scripts/create-lots-of-content/create-100-pages.php
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;
}


21 changes: 21 additions & 0 deletions apps/cms/scripts/create-lots-of-content/run.php
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";
Binary file added apps/cms/scripts/create-lots-of-content/tiny.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.

0 comments on commit 117a5a5

Please sign in to comment.