From 9eb5cba55e6426f1e767b88bd6d8be50dfd9a612 Mon Sep 17 00:00:00 2001 From: Valentin Lab Date: Sun, 17 Feb 2019 11:13:37 +0100 Subject: [PATCH] fix: dev: better caching of ``_get_rec_depth``. --- bin/compose-core | 17 ++++++++++++----- 1 file changed, 12 insertions(+), 5 deletions(-) diff --git a/bin/compose-core b/bin/compose-core index de10c53..3790144 100755 --- a/bin/compose-core +++ b/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