Skip to content

Autocomplete --url (autoclosed by history purge)#5675

Closed
iandunn wants to merge 9883 commits intowp-cli:masterfrom
iandunn:autocomplete-urls
Closed

Autocomplete --url (autoclosed by history purge)#5675
iandunn wants to merge 9883 commits intowp-cli:masterfrom
iandunn:autocomplete-urls

Conversation

@iandunn
Copy link
Copy Markdown
Contributor

@iandunn iandunn commented Sep 15, 2022

This was closed by the history purge, and has been restarted in #5704.


Fixes #5256

This adds tab completion for the global --url parameter, to make it more convenient to type long URLs in Multisite environments.

> wp cron event list --url=foo
foo.example.org       foot.example.org      football.example.org

This is just a rough sketch at the moment. There are some unanswered questions, and I haven't even tried running the tests. I'd just like to get feedback on the general approach etc before putting too much time into it.

Are there any fundamental things that should change? Or does it basically look good and just needs to be finished?

WhiteWinterWolf and others added 30 commits April 18, 2021 11:57
Update docblocks for methods that accept error objects
…ull-value

Harden error message on failed cache directory creation
Add missing `$pipes` variables when creating processes
…5-08

Update Composer dependencies - 2021-05-08
danielbachhuber and others added 22 commits July 7, 2022 09:28
…-plugins

Add `johnpbloch/wordpress-core-installer` to `allowed-plugins`
According to the docblock, the method is supposed to default to the current working dir, but in reality it could return `null` if nothing was found.

This breaks other methods like `::set_wp_root()` which expect a string.

Prevents PHP deprecation notices because `null` was passed to `realpath()`.
Prevents PHP deprecation notices when inadvertently passing `null` to the function and thus `rtrim`.
…-in-test-scenarios

Require `v3.1.6` of `wp-cli/wp-cli-tests`
Co-authored-by: Alain Schlesser <alain.schlesser@gmail.com>
Co-authored-by: Daniel Bachhuber <daniel.bachhuber@automattic.com>
…or-admin-context-logix

Use different action for admin context logic
@iandunn
Copy link
Copy Markdown
Contributor Author

iandunn commented Sep 15, 2022

@schlessera , do you have any thoughts on this?

@schlessera
Copy link
Copy Markdown
Member

schlessera commented Oct 6, 2022

@iandunn Thanks for the work on this. It would certainly be nice to have autocompletion for URLs.
The main difficulty here is obviously the scalability. How can we make sure that this doesn't just block WP-CLI for a few minutes on a large network?
One approach could be to add heuristics that try to guess whether the approach would be fast enough or not, based on metrics that are quick to fetch and evaluate.
Another approach could be to launch the "site gathering" in a separate, monitored process with a timeout.
We should discuss and test approaches like that to ensure that autocompletion is kept responsive enough even in some worst case scenarios. Responsiveness is very important for autocompletion, otherwise it quickly veers from help to hinderance.
Happy to discuss here or help unblock.

@iandunn
Copy link
Copy Markdown
Contributor Author

iandunn commented Oct 6, 2022

add heuristics that try to guess whether the approach would be fast enough or not, based on metrics that are quick to fetch and evaluate.

How about something simple, like only enabling autocompletion if wp_is_large_network() is false?

Combined with caching an alphabetized list of domains/paths on disk, that seems like it'd be performant. If it's not, we can always drop the number to 5,000 or whatever is performant.

Psuedocode:

on wpcli shutdown
    if wp_is_large_network
        return

    if cache older than 12 hours || # of sites has changed since last cache generation
        launch background process
            wpdb->get_results( SELECT domain, path FROM wpdb->blogs ORDER BY domain, path ASC )
            write to ~/.wp-cli/cache/url-autocomplete.txt

That way the only potential bottleneck for the user is processing the cache file:

on url autocomplete trigger
    if wp_is_large_network
        write "can't autocomplete with more than wp_is_large_network() sites"
    else
        run autocomplete using cache file

@danielbachhuber
Copy link
Copy Markdown
Member

Proceeding with #5594 for this repository. I've captured this PR to https://gist.github.com/danielbachhuber/f825f836ba8d9ed5270a8f1eff0e5d3d in case this PR is auto-closed or broken in some way.

@iandunn iandunn mentioned this pull request Nov 18, 2022
@iandunn iandunn changed the title Autocomplete --url Autocomplete --url (autoclosed by history purge) Nov 18, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Provide an easier way to specify target site (--url)