In vagrant_drush_init there is a call to _drush_vagrant_help_text() that sets the context: 'vagrant_help_text'. This function call results in a call through to vagrant itself, which is expensive.
It seems like the 'vagrant_help_text' is only actually used in one place anyway, as the description of the 'vagrant' command in vagrant_drush_command().
The call through to vagrant happens on every Drush bootstrap, which is especially painful when doing a Drush make. Drush Vagrant will significantly slow down a Drush make!
I'm not 100% sure of the purpose of these calls to vagrant, are you trying to fetch the help text from Vagrant and provide it as Drush help text too?
Comments
Comment #1
helmo commentedIntegrating help text from vagrant itself is indeed part of the intended behavior.
Also to know witch sub-commands are available for us to use.
We might be able to use drush_cache_set() to lessen the load...
Comment #2
steven jones commentedActually looking at the code in
drush_vagrant_initI wonder if most of that could be moved into something that only runs on execution of a drush-vagrant Drush command. You could so something like this:And then in the vagrant command definitions you could do something like:
Comment #3
ergonlogicHmm... I'd thought by moving that code from hook_drush_load() to hook_drush_init() it would only run for drush-vagrant commands. I also wasn't aware you could extend the command array so easily.
I've implemented the suggestions above. Both only running vagrant-specific stuff on only drush-vagrant commands, and saving the results of the most common expensive operations to the drush cache.
Comment #4
steven jones commentedGetting there, but I think that the drush caches are global, so your cache keys need to be more specific, at least prefixed with 'drush_vagrant_', or possibly better, use the 'bin' argument to put them all in a 'drush-vagrant' bin.
Comment #5
ergonlogicWent with the latter option.
Comment #6
helmo commentedI'm not sure we'd want to cache the project root. Wouldn't that get messy when you work with multiple vagrant projects?
Anyway the code below looks like it could try to define PROJECT_PATH twice.
And related, when your not inside a project directory 'drush vbl' fails.
_drush_vagrant_get_project_path() through drush_vagrant_check_project sets an error.
Comment #7
ergonlogicYeah, that's confusing, but we're ony caching the PROJECTS_PATH. So, only '~/vagrant/projects' by default. I think it'd be worthwhile to change the name of the constant to PROJECTS_DIR, or something.
I'll check out the error with vbl.
Comment #8
ergonlogicHmm... It looks like I had an un-pushed commit, re-working how we now auto-load aliases, and climbs up the tree to determine our project's path. Sorry about that. 'drush vbl' works fine for me.
Comment #9
helmo commentedok, after a git pull vbl is working again.
Comment #10
helmo commentedThen maybe the cache key should also have the extra S?
So cache['projects_root'] instead of $cache['project_root'] ...
Comment #11
helmo commentedThe vagrant-blueprints command does not seem to need the 'requires_vagrant' flag.
Would it be usefull to have a similar flag indicate if a command needs a valid vagrant project directory?
This could be useful to generalize a check I'm proposing in #1790036: Issueing `drush vagrant delete project-name` behaves badly by promise to delete the pwd
Comment #12
ergonlogicI think it's a good idea to have a 'requires_vagrant_project' flag, or similar. At what point do you suggest we check this?
Comment #13
helmo commentedI guess vagrant_drush_init() would be the place. Then we could generate an error there, through drush_vagrant_check_project() if the requirement is not met.
Comment #14
clemens.tolboomPlease do so. This would help #1790168: `vagrant aliases` doesn't validate a project directory forward too.
Comment #15
helmo commented@ergonlogic: Do you agree with #10
The patch implements the 'requires_vagrant_project' flag.
edit: typo
Comment #16
ergonlogicThe change in #10 makes sense. But in this patch, I'm pretty sure that vagrant-list and vagrant-user should not require a vagrant project.
Comment #17
helmo commentedThe patch from #15 does not add the flag for vagrant-list vagrant-user.
Comment #18
ergonlogicRight, sorry. I parsed the patch incorrectly when reading it.
Comment #19
helmo commentedCommitted #15 to 7.x-2.x
Now we can get back to #10
and #11
Also committed to 7.x-2.x
Comment #20
franskuipers commentedPatch for #10
Changed also $user_settings['vagrant']['project_root'] to $user_settings['vagrant']['projects_root']
and $project_root to $projects_root
#11 is solved in this commit
Comment #21
franskuipers commentedComment #22
mglamanPatch in #20 saved me. It's hijacking and breaking other drush commands - like make_local. Drush Vagrant was hijacking the command only making it partially build.
Comment #23
mglamanFalse alarm, sorry.