Loki_SetupAccelerator
Speeds up bin/magento setup:upgrade by skipping work whose inputs did not change since the last run. The end
result in the database and in app/etc stays the same.
| Step | What Magento does on every run | What this module does |
|------|--------------------------------|-----------------------|
| Declarative schema | Reads and validates all db_schema.xml files, reads the full DB structure table by table, diffs both | Skips the diff when the db_schema.xml/db_schema_whitelist.json files, the enabled modules, the Magento version and the DB structure of all tables in those files (4 bulk information_schema queries) are unchanged since the last successful run. Tables the declarative schema does not manage, like the per-store index tables that every full reindex swaps with their replicas, are ignored |
| bin/magento setup:db:status | Runs the same full declarative schema diff | Reports the declarative schema as up to date when that same fingerprint still matches |
| Magento\Indexer\Setup\Recurring | Drops and recreates the mview triggers of every scheduled indexer | Keeps enabled, idle views with an existing changelog table; TriggerCleaner (which runs right after) rewrites only missing or outdated triggers |
| Magento\ConfigurableSampleData\Setup\RecurringData | Runs reindexAll() for all indexers | Reindexes only invalid indexers, unless a patch or module version was applied in the same run |
| Hyva\Theme\Setup\Recurring | Boots a second ObjectManager with the frontend area to regenerate app/etc/hyva-themes.json | Skips when the file, the enabled modules, the module paths, the hyva_config_generate_before observers (and their class files) and vendor/composer/installed.json are unchanged |
| Loki\Components / LokiCheckout\Core Recurring | Reloads all modules and rewrites app/etc/config.php, even with nothing to enable | Skips when all modules of their module.xml sequence are enabled |
Measured in a Hersir environment (Mage-OS 2.4.9, MariaDB 11.8, 414 modules incl. Hyvä and sample data),
setup:upgrade --keep-generated without changes: ~50s without, ~9.3s with this module.
Any manual change to the database structure or to the mview triggers is still repaired, because the fingerprints
include the actual DB structure and TriggerCleaner still checks every trigger.
Installation
Install this package via composer:
composer require loki/magento2-setup-accelerator
Next, enable this module:
bin/magento module:enable Loki_SetupAccelerator
The first setup:upgrade after enabling still runs everything and stores the fingerprints in
var/loki_setup_accelerator/fingerprints.json. They are stored in a file (and not in the database), so that they
survive a database re-import. The declarative schema fingerprint includes the DB structure, so an imported
database with another structure still gets the full run. Removing that file forces a full run of every step.
Usage
Disable the accelerator for a single run (and drop the stored schema fingerprint):
LOKI_SETUP_ACCELERATOR=0 bin/magento setup:upgrade
The options --dry-run, --safe-mode, --data-restore and --convert-old-scripts always run the full
declarative schema step. Setups with more than one database connection (split database) are never skipped.
When the command is followed by a full reindex or a Hyvä build anyway (like in an automated install), the two slowest recurring scripts can be deferred to those:
LOKI_SETUP_ACCELERATOR_DEFER_REINDEX=1 LOKI_SETUP_ACCELERATOR_DEFER_HYVA=1 bin/magento setup:upgrade bin/magento index:reindex bin/magento hyva:config:generate
LOKI_SETUP_ACCELERATOR_DEFER_REINDEX=1skips the full reindex ofMagento\ConfigurableSampleData\Setup\RecurringData. When a patch or module version was applied in the same run, all indexers are marked invalid instead, so that the nextindex:reindex(or the indexer cron) picks them up.LOKI_SETUP_ACCELERATOR_DEFER_HYVA=1skipsHyva\Theme\Setup\Recurring, soapp/etc/hyva-themes.jsonis only regenerated by the nextbin/magento hyva:config:generate.
Each run writes one report to var/log/loki_setup_accelerator.log, with the command, the total duration, the
time not covered by any measured phase (bootstrap, module list update, cache cleaning, code generation), the duration
of all measured phases (declarative schema, fingerprints, patches, every recurring script, trigger cleaner, config
import) and the skipped or deferred steps.
Current status
@dev
to the composer command.
Support
For getting support, create an Issue under the following project URL:
https://gitlab.yireo.com/loki-extensions-dev/Loki_SetupAccelerator.git
Composer details
Loki_SetupAcceleratorloki/magento2-setup-accelerator
ext-json: *
magento/framework: ^103.0
magento/module-deploy: ^100.4
magento/module-indexer: ^100.4
php: >=8.2 <8.6