Skip to content

Commit

Permalink
Performance improvement: proxy_auto became to cache a result.
Browse files Browse the repository at this point in the history
  • Loading branch information
kou1okada committed Apr 19, 2015
1 parent 5b61ba2 commit 2ecade0
Showing 1 changed file with 25 additions and 3 deletions.
28 changes: 25 additions & 3 deletions apt-cyg
Original file line number Diff line number Diff line change
Expand Up @@ -522,10 +522,21 @@ function apt-cyg-upgrade-self ()

function proxy_auto ()
{
local proxy=$("${WGET[@]}" --no-proxy -q -O - wpad/wpad.dat \
| grep PROXY \
| sed -e 's/^.*PROXY\s*\([^"]*\).*$/http:\/\/\1/g')
local hash="$(ipconfig 2>&1 | md5sum -b | awk '{print $1}')"
local cache="/tmp/apt-cyg.proxy.$hash"
local last="$(stat -c %Y "$cache" 2>/dev/null)"
local now="$(date +%s)"
local proxy

[ -n "$OPT_PROXY_FORCE_REFRESH" ] && last=0
if (( (now - ${last:-0}) < OPT_PROXY_REFRESH_INTERVAL )); then
proxy="$(<"$cache")"
else
proxy=$("${WGET[@]}" --no-proxy -q -O - wpad/wpad.dat \
| grep PROXY \
| sed -e 's/^.*PROXY\s*\([^"]*\).*$/http:\/\/\1/g')
echo "$proxy" > "$cache"
fi
[ -n "$proxy" ] && proxy_set "$proxy"
}

Expand Down Expand Up @@ -1127,6 +1138,7 @@ force_remove=""
force_fetch_trustedkeys=""
no_verify=""
OPT_PROXY=${APT_CYG_PROXY:-auto}
OPT_PROXY_REFRESH_INTERVAL=${APT_CYG_PROXY_REFRESH_INTERVAL:-86400} # 86400s = 1day
OPTS4INHERIT=()
SETUP_EXE="setup-$(current_cygarch).exe"
YES_TO_ALL=false
Expand Down Expand Up @@ -1188,6 +1200,16 @@ function parse_args ()
shift 2 || break
;;

--proxy-force-refresh)
OPT_PROXY_FORCE_REFRESH="$1"
shift
;;

--proxy-refresh-interval)
OPT_PROXY_REFRESH_INTERVAL="$2"
shift 2 || break
;;

--completion-get-subcommand)
OPT_COMPLETION_GET_SUBCOMMAND="$1"
shift
Expand Down

0 comments on commit 2ecade0

Please sign in to comment.