This is our collection of commands for n98-magerun2
.
The commands allow to speed up compilation and deployment of static assets, as well
as few other helper commands for Magento 2.
sudo yum -y install https://extras.getpagespeed.com/release-latest.rpm
sudo yum -y install n98-magerun2-module-getpagespeed
cd /path/to/magento2
# Get tuned Varnish parameters specifc to your Magento 2 instance
n98-magerun2 varnish:tuned
# Get active themes
n98-magerun2 dev:theme:active
Gets tuned Varnish parameters specifc to your Magento 2 instance. It will find the category with largest number of products and provide Varnish parameters that will help you to avoid "Backend Fetch Failed" error as detailed in documentation. Example output:
Varnish params: -p http_resp_hdr_len=54684 -p http_resp_size=79260 -p workspace_backend=112028 Largest product category has this number of products: 2604
Simply copy-paste the suggested configuration bits to e.g. /etc/varnish/varnish.params
or otherwise
specify as startup parameters to Varnish.
Allows to get list of used themes. Example output (suitable for deploy static command):
--theme Swissup/argento-pure2
This is useful for scripts to facilitate faster builds.
Many Magento 2 themes come bundled with many actual themes, and deploying static assets takes huge time. All because you unnecessarily minify a ton of CSS and Javascript files for themes which are not even in use!
You can deploy just the used themes with:
bin/magento setup:static-content:deploy $(n98-magerun2 dev:theme:active)
This is used in our zero-downtime deployment program,
clearmage2
.
Another way to speed up deployment of static files is by generating them only for actually used locales. I truly believe that Magento 2 is dumb as f* of not doing this by default.
Only if you use n98-magerun2 deploy:mode:set production
command, it is smart enough to generate
statics only for used locales. But this command is dumb, because when you use it, you cannot parallelize
deployment, and then again, you cannot deploy for only active themes, as above allows.
So you can get list of actively used locales with n98-magerun2 deploy:locale:active
and pass it
over to deployment command:
#> n98-magerun2 deploy:locale:active #> en_US en_GB
Combining all the things together for a no-dumb and much quicker static deployment:
THEMES=$(n98-magerun2 dev:theme:active)
LOCALES=$(n98-magerun2 deploy:locale:active)
php ./bin/magento setup:static-content:deploy --jobs=$(nproc) ${THEMES} ${LOCALES}
This is also used in our zero-downtime deployment program,
clearmage2
.
This command trims entries for the search_query
for queries which produce no results and were
made more than a month ago. Helps to prevent too much unnecessary database bloating and thus
improves performance.
There is no output on success. It is suitable to be set up into a @monthly
cron, e.g.:
@monthly n98-magerun2 db:maintain:search-query --root-dir=/path/to/magento2
Extra switch for trimming based on popularity, e.g. remove all with popularity < 25
This will install our RPM repository, n98-magerun2
and the module:
sudo yum install https://extras.getpagespeed.com/release-latest.rpm
sudo yum install n98-magerun2-module-getpagespeed
Just place the files over to /usr/local/share/n98-magerun2
.