#!/usr/bin/env bash

unique_field="relative_path"
#unique_field="artifact"

paging_limit=2000
#paging_limit=100
offset_limit=70000

data_file="tmpf"
tmp_file2="tmpf2"
tmp_file3="tmpf3"

http ':24817/pulp/api/v3/content/file/files/?limit=2000&offset=0' \
    | jq -r '[.results[] | .'"${unique_field}"']' > ${data_file}

for offset in $(seq 2000 ${paging_limit} ${offset_limit})
do
    echo ". + " > ${tmp_file2}
    http ':24817/pulp/api/v3/content/file/files/?limit='"${paging_limit}"'&offset='"${offset}"'' \
        | jq -r '[.results[] | .'"${unique_field}"']' >> ${tmp_file2}
    jq -f ${tmp_file2} ${data_file} > ${tmp_file3}
    cat ${tmp_file3} > ${data_file}
    echo "${offset}: $(jq -r 'unique[]' ${data_file} | wc -l)"
done

unique_values=$(jq -r 'unique[]' ${data_file} | wc -l)
echo "Expected: ${offset_limit}"
echo "Actual: ${unique_values}"
