Skip to content

Commit

Permalink
Merge pull request #85 from lukealbao/lazy-compression
Browse files Browse the repository at this point in the history
Compress only if saving to backend
  • Loading branch information
pzeballos authored Oct 17, 2024
2 parents d823b2e + edaf161 commit b2e2172
Showing 1 changed file with 11 additions and 4 deletions.
15 changes: 11 additions & 4 deletions hooks/post-command
Original file line number Diff line number Diff line change
Expand Up @@ -39,19 +39,26 @@ else
exit 0
fi

if compression_active; then
ACTUAL_PATH="${CACHE_PATH}"
already_compressed='false'
needs_compression() {
compression_active && [ "$already_compressed" = 'false' ]
}
do_compress() {
ACTUAL_PATH=$(mktemp)
compress "${CACHE_PATH}" "${ACTUAL_PATH}"
else
ACTUAL_PATH="${CACHE_PATH}"
fi
already_compressed='true'
}

for LEVEL in "${SAVE_LEVELS[@]}"; do
KEY=$(build_key "${LEVEL}" "${CACHE_PATH}" "${COMPRESS}")

if [ "$(plugin_read_config FORCE 'false')" != 'false' ] ||
! backend_exec exists "${KEY}"; then
echo "Saving ${LEVEL}-level cache of ${CACHE_PATH}"
if needs_compression; then
do_compress
fi
backend_exec save "${KEY}" "${ACTUAL_PATH}"
else
echo "Cache of ${LEVEL} already exists, skipping"
Expand Down

0 comments on commit b2e2172

Please sign in to comment.