Browse Source

fix: dev: better caching of ``_get_rec_depth``.

hostresources
Valentin Lab 6 years ago
parent
commit
9eb5cba55e
  1. 17
      bin/compose-core

17
bin/compose-core

@ -1378,13 +1378,17 @@ export -f get_service_deps
## XXXvlab: cache was disabled because improper. Indeed, this needs to cache
## 'depths' full state. Second, it should be
_rec_get_depth() {
local elt=$1 dep deps max cache_file="$state_tmpdir/$FUNCNAME.cache.$1.$(declare -pA depths | md5_compat)"
local elt=$1 dep deps max
[ "${depths[$elt]}" ] && return 0
if [ -e "$cache_file" ]; then
# debug "$FUNCNAME: cache hit ($*)"
local cache_file="$state_tmpdir/$FUNCNAME.cache.$1.$(declare -pA depths | md5_compat)"
if [ -e "$cache_file.depths" ]; then
#debug "$FUNCNAME: cache hit ($*) - $cache_file.depths"
while read-0 k v; do
depths["$k"]="$v"
done < "$cache_file"
done < "$cache_file.depths"
while read-0 k v; do
visited["$k"]="$v"
done < "$cache_file.visited"
return 0
fi
@ -1410,7 +1414,10 @@ _rec_get_depth() {
done
# debug "Setting depth[$elt] to $((max + 1))"
depths[$elt]=$((max + 1))
array_kv_to_stdin depths > $cache_file
array_kv_to_stdin depths > "$cache_file.depths"
array_kv_to_stdin visited > "$cache_file.visited"
# debug "DEPTHS: $(declare -pA depths)"
# debug "$FUNCNAME: caching hit ($*) - $cache_file"
}
export -f _rec_get_depth

Loading…
Cancel
Save