-
Notifications
You must be signed in to change notification settings - Fork 847
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Speed up checking for vvv-hosts
files
#1182
Speed up checking for vvv-hosts
files
#1182
Conversation
Only look 2 directories deep rather than unlimited.
vvv-hosts
filesvvv-hosts
files
This could break site provisioners that rely on scanning for vvv-hosts multiple levels deep. Instead i think we should just restrict this to 4 levels deep bringing the hosts file on the hosts machine in sync with the hosts file on the VM. |
To support other provisioners/setups such as WordPress/meta-environment
@LoreleiAurora I've rewritten the line to be more generic but restricted to 4 levels deep. Have checked locally using WordPress/meta-environment and it still picks up the vvv-hosts files but is still much faster in provisioning, vagrant ssh etc. |
Looking at this again we need to come up with a different way to do the scan. the scan 4 levels deep in provision-site.sh is relative to a site dir where as this is relative to the www root. |
This makes sense, I don't think more than 4 levels deep is necessary, as long as the docs are updated |
Looking into it a bit more, the vvv-hosts code within Vagrantfile only looks within the www root hierarchy whereas the docs state that with custom paths the site local_dir path could be anywhere. With a custom local_dir the vvv-hosts file would only be used within provision-site.sh so any custom hosts would have to be duplicated in vvv-custom.yml otherwise nothing would be added to the hosts file on the hosts machine. At least that's how i'm reading it. As the docs state that using vvv-custom.yml is the recommendation for setting hosts and a vvv-hosts file is only for backwards compatibility would a better solution be to see if hosts have been set in vvv-custom.yml and if not only then to look within that sites' local_dir to find a vvv-hosts file? |
Personally i would go for the approach of
This approach would prevent breaking bc. @jeremyfelt @tomjn Thoughts? |
Scan restricted to directories 4 levels deep
How about this? Covers point 1. Priority is hosts defined in vvv-custom.yml then on each site checks within the local_dir 4 directories deep for any vvv-hosts files to add those hosts. |
Vagrantfile
Outdated
@@ -71,6 +64,14 @@ vvv_config['sites'].each do |site, args| | |||
|
|||
vvv_config['sites'][site] = defaults.merge(args) | |||
|
|||
site_local_dir = vvv_config['sites'][site]['local_dir'] | |||
site_host_paths = Dir[File.join(site_local_dir, '*', 'vvv-hosts'), File.join(site_local_dir, '*', '*', 'vvv-hosts'), File.join(site_local_dir, '*', '*', '*', 'vvv-hosts'), File.join(site_local_dir, '*', '*', '*', '*', 'vvv-hosts')] |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
You can shorten these 2 lines to
site_host_paths = Dir.glob(Array.new(4) {|i| vvv_config['sites'][site]['local_dir'] + '/*'*(i+1) + '/vvv-hosts'})
I have left a comment inline. Once this change is made this can be merged and a seperate ticket opened for |
Have made that change, getting used to using Ruby so didn't realise that that was possible. |
The existing recursive blob causes massive slowdown of everything (provision, ssh etc) once I've got a few projects setup, especially if they have numerous directories.
This change limits the lookups to only look at the primary directory and a
provision
subfolder rather than unlimited depth. This matches what is documented, though other code such as provision-site.sh still looks 4 levels deep.On my setup doing
vagrant ssh
returns in seconds rather than potentially minutes. Should be useful in situations such as https://jjj.blog/2016/05/slow-vagrant/Related: #595