Skip to content

Instantly share code, notes, and snippets.

@geolffreym
Created January 18, 2021 01:16
Show Gist options
  • Save geolffreym/e502cbf44ed4b4c375934452e5f93c1f to your computer and use it in GitHub Desktop.
Save geolffreym/e502cbf44ed4b4c375934452e5f93c1f to your computer and use it in GitHub Desktop.
function db.oplog.values.hashes () {
local host
local dbAddr
host=${2:-${ORBIT_DB_HOST}}
dbAddr=$(rawurlencode "${1}")
_curl "${host}/db/${dbAddr}/oplog/values" | jsawk "'return this.hash'" -a "'return this.join(\" \")'"
}
function db.heads.pin () {
declare -a hashes=()
for hash in $(db.oplog.values.hashes "${@}")
do
hashes+=("$hash")
if [[ ${#hashes[@]} -ge ${ORBIT_DB_PIN_BATCH_COUNT} ]]; then
echo "Pinning ${hashes[*]}"
ipfs pin add --progress --timeout "${ORBIT_DB_PIN_TIMEOUT}" "${hashes[@]}"
hashes=()
sleep 30
fi
done
# Pin leftover hashes batch < 100
echo "Pinning ${hashes[*]}"
ipfs pin add --progress --timeout "${ORBIT_DB_PIN_TIMEOUT}" "${hashes[@]}"
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment