fix: improved efficiency of deduplication in verification.json script

pull/4713/head
Favour 1 month ago
parent f2bede3f5f
commit 4c2786b799
  1. 22
      typescript/infra/scripts/dedupe-verification-json.sh

@ -19,17 +19,33 @@ verification_files=$(find "$config_dir" -name "verification.json")
for input_file in $verification_files; do
echo "Processing file: $input_file"
# Check if the file contains valid JSON
if ! jq empty "$input_file" &>/dev/null; then
echo "Error: $input_file contains invalid JSON. Skipping file."
continue
fi
# Get the list of chains
chains=$(jq -r 'keys[]' "$input_file")
# Iterate through each chain and deduplicate its array in-place
# Iterate through each chain and deduplicate its array
for chain in $chains; do
echo "Deduplicating array for chain: $chain"
jq ".$chain |= (reduce .[] as \$item ([]; if any(.[]; .address == \$item.address) then . else . + [\$item] end))" "$input_file" > temp.json && mv temp.json "$input_file"
# Deduplicate in memory and only write back if changes are made
updated_json=$(jq ".$chain |= unique_by(.address)" "$input_file")
# Only overwrite if there are changes
if [ "$updated_json" != "$(cat "$input_file")" ]; then
echo "$updated_json" > "$input_file"
echo "File has been updated and deduplicated in-place: $input_file"
else
echo "No changes needed for $input_file"
fi
done
echo "File has been deduplicated in-place: $input_file"
echo
done
echo "All verification.json files have been processed."

Loading…
Cancel
Save