From 0b62cf2bc4e221cb4e6279cfc2b447083f19b028 Mon Sep 17 00:00:00 2001 From: fbt Date: Fri, 25 Sep 2015 17:56:23 +0300 Subject: [PATCH] Don't query AUR for each package dammit --- prm | 33 ++++++++++++++++++++++----------- 1 file changed, 22 insertions(+), 11 deletions(-) diff --git a/prm b/prm index 579e593..59d50a6 100755 --- a/prm +++ b/prm @@ -66,25 +66,26 @@ aur.info() { aur.get_updates() { declare -a foreign_packages - declare p_aur_info p_localver p_aur_version + declare p_aur_info p_localver p_aur_version aur_api_multireq aur_api_data read -d '' -r -a foreign_packages < <( pacman -Qqm ) for p in "${foreign_packages[@]}"; do - unset p_aur_info - read -r p_aur_info < <( aur.info "$p" ) + aur_api_multireq+="&arg\[\]=$p" + done - if [[ "$p_aur_info" ]]; then - read -r p_aur_version < <( - jshon -e results -e Version -u <<< "$p_aur_info" - ) + aur_api_data=$( curl "${cfg_curl_opts[@]}" "${cfg_aur_api}?type=multiinfo${aur_api_multireq}" ) - read -r _ p_localver < <( pacman -Q "$p" ) + aur_api_data_length=$( jshon -e results -l <<< "$aur_api_data" ) + (( aur_api_data_length-- )) + for (( n=0; n<=aur_api_data_length; n++ )); do + read -r n_name < <( jshon -e results -e "$n" -e Name -u <<< "$aur_api_data") + read -r n_version < <( jshon -e results -e "$n" -e Version -u <<< "$aur_api_data" ) + read -r l_name l_version < <( pacman -Q "$n_name" ) - if (( $(vercmp "$p_aur_version" "$p_localver") )); then - printf '%s\n' "$p" - fi + if (( $(vercmp "$n_version" "$l_version") )); then + printf '%s\n' "$n_name" fi done } @@ -275,6 +276,11 @@ main() { case "$action" in (get) + [[ "$package" ]] || { + usage + return 1 + } + [[ -d "$cfg_workdir" ]] || { mkdir -p "$cfg_workdir" || { err "Can't create workdir: %s\n" "$cfg_workdir" @@ -315,6 +321,11 @@ main() { ;; (search) + [[ "$package" ]] || { + usage + return 1 + } + if (( flag_search_aur )); then aur.search "$package" || { err "No packages found\n"