Skip to content

Commit c1482a0

Browse files
committed
perf: batch drush module enables into single calls
Replace ~40 sequential drush pm:enable calls (each spawning a separate PHP process) with a single drush pm:install call passing all modules. Eliminates redundant Drush bootstraps, dependency resolutions, and intermediate cache rebuilds. Same approach for custom NDX modules.
1 parent c029ba0 commit c1482a0

1 file changed

Lines changed: 43 additions & 60 deletions

File tree

cloudformation/scenarios/localgov-drupal/docker/scripts/init-drupal.sh

Lines changed: 43 additions & 60 deletions
Original file line numberDiff line numberDiff line change
@@ -503,34 +503,38 @@ enable_localgov_modules() {
503503
localgov_workflows_notifications
504504
"
505505

506-
# Count total modules for progress reporting
507-
local total_modules=0
506+
# Filter to only modules that are available and not yet enabled
507+
local modules_to_enable=""
508+
local skipped=0
508509
for module in $LOCALGOV_MODULES; do
509-
total_modules=$((total_modules + 1))
510-
done
511-
512-
# Enable each module if available (ignore errors for missing optional modules)
513-
# Progress spans 72% to 75% across modules
514-
local module_index=0
515-
for module in $LOCALGOV_MODULES; do
516-
module_index=$((module_index + 1))
517-
local module_progress=$((72 + (3 * module_index / total_modules)))
518-
update_status "Modules" "Enabling module ${module_index}/${total_modules}: ${module}" "$module_progress"
519-
log "Checking module: $module"
520510
if ./vendor/bin/drush pm:list --status=disabled --type=module --field=name 2>/dev/null | grep -q "^${module}$"; then
521-
log " Enabling $module..."
522-
local module_output
523-
module_output=$(./vendor/bin/drush pm:enable "$module" --yes 2>&1) || true
524-
if [ -n "$module_output" ]; then
525-
echo "$module_output" | while IFS= read -r line; do
526-
log " $line"
527-
done
528-
fi
511+
modules_to_enable="$modules_to_enable $module"
529512
else
513+
skipped=$((skipped + 1))
530514
log " $module already enabled or not available, skipping"
531515
fi
532516
done
533517

518+
if [ -z "$modules_to_enable" ]; then
519+
log "All LocalGov modules already enabled"
520+
return 0
521+
fi
522+
523+
local count
524+
count=$(echo $modules_to_enable | wc -w | tr -d ' ')
525+
log "Enabling $count LocalGov modules in a single batch (skipped $skipped)..."
526+
update_status "Modules" "Enabling $count LocalGov modules in batch..." 73
527+
528+
# Single drush call: one PHP bootstrap, one dependency resolution, one final hook_modules_installed
529+
local batch_output
530+
batch_output=$(./vendor/bin/drush pm:install $modules_to_enable --yes 2>&1) || true
531+
if [ -n "$batch_output" ]; then
532+
echo "$batch_output" | while IFS= read -r line; do
533+
log " $line"
534+
done
535+
fi
536+
537+
update_status "Modules" "LocalGov modules enabled" 75
534538
return 0
535539
}
536540

@@ -540,47 +544,26 @@ enable_custom_modules() {
540544

541545
cd "$DRUPAL_ROOT"
542546

543-
# Helper function to enable a module without problematic piping
544-
# The | while read pattern causes SIGPIPE issues with drush
545-
enable_module() {
546-
local module_name="$1"
547-
local module_dir="$DRUPAL_ROOT/web/modules/custom/$module_name"
548-
549-
if [ -d "$module_dir" ]; then
550-
log "Enabling $module_name module..."
551-
# Use direct execution with output capture and retry for deadlocks
552-
local output
553-
if output=$(run_drush_with_retry ./vendor/bin/drush pm:enable "$module_name" --yes); then
554-
log " $module_name enabled successfully"
555-
[ -n "$output" ] && log " Output: $output"
556-
return 0
557-
else
558-
log " Warning: $module_name enable returned non-zero, but may have succeeded"
559-
[ -n "$output" ] && log " Output: $output"
560-
# Check if actually enabled despite the error using pm:list (filter warning lines)
561-
sleep 2 # Wait for any pending cache writes to complete
562-
local enabled_list
563-
enabled_list=$(./vendor/bin/drush pm:list --status=enabled --type=module --field=name 2>/dev/null | grep -v '\[warning\]' | grep -v 'Drush command' | tr '\n' ' ')
564-
if echo "$enabled_list" | grep -qw "$module_name"; then
565-
log " Verified: $module_name is enabled"
566-
return 0
567-
fi
568-
log " Module $module_name not in enabled list - continuing anyway"
569-
# Return 0 to avoid script exit - module may still work
570-
return 0
571-
fi
547+
# Collect custom modules that exist on disk
548+
local NDX_MODULES="ndx_demo_banner ndx_welcome ndx_walkthrough ndx_aws_ai ndx_council_generator"
549+
local custom_to_enable=""
550+
for module in $NDX_MODULES; do
551+
if [ -d "$DRUPAL_ROOT/web/modules/custom/$module" ]; then
552+
custom_to_enable="$custom_to_enable $module"
572553
else
573-
log "$module_name module not found at $module_dir, skipping"
574-
return 0
554+
log "$module module not found, skipping"
575555
fi
576-
}
577-
578-
# Enable modules in dependency order
579-
enable_module "ndx_demo_banner" # Story 1.10
580-
enable_module "ndx_welcome" # Story 1.11
581-
enable_module "ndx_walkthrough" # Epic 2
582-
enable_module "ndx_aws_ai" # Epic 3-4 dependency
583-
enable_module "ndx_council_generator" # Epic 5 - requires ndx_aws_ai
556+
done
557+
558+
if [ -n "$custom_to_enable" ]; then
559+
local count
560+
count=$(echo $custom_to_enable | wc -w | tr -d ' ')
561+
log "Enabling $count custom NDX modules in batch..."
562+
update_status "Modules" "Enabling $count custom NDX modules..." 76
563+
local output
564+
output=$(run_drush_with_retry ./vendor/bin/drush pm:install $custom_to_enable --yes) || true
565+
[ -n "$output" ] && log " $output"
566+
fi
584567

585568
# Clear caches before verification to ensure module system is up to date
586569
log "Rebuilding cache before module verification..."

0 commit comments

Comments
 (0)