From f994b07a2cd0e6470ce4ac47ece7d3d777748c2c Mon Sep 17 00:00:00 2001 From: mig4 <42101611+mig4@users.noreply.github.com> Date: Sat, 27 Oct 2018 20:05:02 +0100 Subject: [PATCH] Optimise listing all plugins When checking if a plugin is installed (to display a flag) it is not necessary to loop through all installed plugins, since we already have a name we can check directly. Also expand test case to test this code path too. --- lib/commands/plugin-list-all.sh | 5 +---- test/fixtures/dummy_plugins_repo/plugins/dummy | 1 + test/plugin_list_all_command.bats | 2 ++ 3 files changed, 4 insertions(+), 4 deletions(-) create mode 100644 test/fixtures/dummy_plugins_repo/plugins/dummy diff --git a/lib/commands/plugin-list-all.sh b/lib/commands/plugin-list-all.sh index 84381b39..5bf97867 100644 --- a/lib/commands/plugin-list-all.sh +++ b/lib/commands/plugin-list-all.sh @@ -13,10 +13,7 @@ plugin_list_all_command() { source_url=$(get_plugin_source_url "$index_plugin_name") installed_flag="" - for local_plugin in "$plugins_local_path"/*; do - local_plugin_name=$(basename "$local_plugin") - [[ "$index_plugin_name" == "$local_plugin_name" ]] && installed_flag="*" - done + [[ -d "${plugins_local_path}/${index_plugin_name}" ]] && installed_flag='*' printf "%-15s %-1s%s\\n" "$index_plugin_name" "$installed_flag" "$source_url" done diff --git a/test/fixtures/dummy_plugins_repo/plugins/dummy b/test/fixtures/dummy_plugins_repo/plugins/dummy new file mode 100644 index 00000000..aa1f9073 --- /dev/null +++ b/test/fixtures/dummy_plugins_repo/plugins/dummy @@ -0,0 +1 @@ +repository = http://example.com/dummy diff --git a/test/plugin_list_all_command.bats b/test/plugin_list_all_command.bats index 1e62251b..1f0a64ac 100644 --- a/test/plugin_list_all_command.bats +++ b/test/plugin_list_all_command.bats @@ -7,6 +7,7 @@ load test_helpers setup() { setup_asdf_dir setup_repo + install_dummy_plugin } teardown() { @@ -16,6 +17,7 @@ teardown() { @test "plugin_list_all list all plugins in the repository" { run plugin_list_all_command local expected="bar http://example.com/bar +dummy *http://example.com/dummy foo http://example.com/foo" [ "$status" -eq 0 ] [ "$output" = "$expected" ]