From 11bd29b444475fb48cc50bb319023f32fc20b631 Mon Sep 17 00:00:00 2001 From: the-sane <3657071+the-sane@users.noreply.github.com> Date: Sun, 26 Mar 2023 19:31:39 -0400 Subject: [PATCH] Paginate API requests to improve speed --- lug-helper.sh | 8 ++++++-- 1 file changed, 6 insertions(+), 2 deletions(-) diff --git a/lug-helper.sh b/lug-helper.sh index 2b4a5c0..714af82 100755 --- a/lug-helper.sh +++ b/lug-helper.sh @@ -1379,14 +1379,16 @@ download_install() { # download_select_install function below if [ "$download_url_type" = "github" ]; then search_key="browser_download_url" + query_string="?per_page=$max_download_items" elif [ "$download_url_type" = "gitlab" ]; then search_key="direct_asset_url" + query_string="?per_page=$max_download_items" else debug_print exit "Script error: Unknown api/url format in ${download_type}_sources array. Aborting." fi # Get the selected download url - download_url="$(curl -s "$contributor_url" | grep -o "$search_key.*$download_file" | cut -d \" -f3)" + download_url="$(curl -s "$contributor_url$query_string" | grep -o "$search_key.*$download_file" | cut -d \" -f3)" # Sanity check if [ -z "$download_url" ]; then @@ -1629,8 +1631,10 @@ download_select_install() { # just above, and the download_install function above if [ "$download_url_type" = "github" ]; then search_key="browser_download_url" + query_string="?per_page=$max_download_items" elif [ "$download_url_type" = "gitlab" ]; then search_key="direct_asset_url" + query_string="?per_page=$max_download_items" else debug_print exit "Script error: Unknown api/url format in ${download_type}_sources array. Aborting." fi @@ -1639,7 +1643,7 @@ download_select_install() { unset download_versions while IFS='' read -r line; do download_versions+=("$line") - done < <(curl -s "$contributor_url" | grep -Po "$search_key.*?[^\\\](\",|\$)" | cut -d \" -f3 | xargs basename -a) + done < <(curl -s "$contributor_url$query_string" | grep -Po "$search_key.*?[^\\\](\",|\$)" | cut -d \" -f3 | xargs basename -a) # Note: match from search_key until ", or EOL (Handles embedded commas and escaped quotes) # Sanity check