pref: fix N+1 issues for dref3 endpoint#2681
Conversation
|
Hey @szabozoltan69, @TKartist, Instead of adding a separate table, I noticed there were still some N+1 issues in the query. After fixing them, the query is now about 4.5× faster. Will this be enough for the current performance improvements? |
|
I tested using the normal endpoint Could you also check if the other iterations still work as before? I used this steps to compare responses For easy data compare, we need to update the existing code to include this in BaseDref3Serializer
Generate dataset from curl http://localhost:8000/api/v2/dref3/ > /tmp/before.json
# other iterationsGenerate dataset from curl http://localhost:8000/api/v2/dref3/ > /tmp/after.json
# other iterationsCompare using dyff #!/bin/bash
PAIRS=(
"/tmp/before.json:/tmp/after.json"
"/tmp/before-iteration1.json:/tmp/after-iteration1.json"
"/tmp/before-iteration2.json:/tmp/after-iteration2.json"
)
SORTED_DIR=$(mktemp -d -t dref3.XXXXXX)
echo "Creating temp directory to store sorted files: $SORTED_DIR"
mkdir -p "$SORTED_DIR"
for pair in "${PAIRS[@]}"; do
IFS=":" read -r BEFORE AFTER <<< "$pair"
echo "Comparing $BEFORE <-> $AFTER"
BEFORE_SORTED="$SORTED_DIR/$(basename "$BEFORE" .json).json"
AFTER_SORTED="$SORTED_DIR/$(basename "$AFTER" .json).json"
jq 'sort_by(.id)' "$BEFORE" > "$BEFORE_SORTED"
jq 'sort_by(.id)' "$AFTER" > "$AFTER_SORTED"
echo "=== Comparing $BEFORE vs $AFTER ==="
dyff between "$BEFORE_SORTED" "$AFTER_SORTED"
echo
done |
I suppose yes! |
I also tested, via the CSV output, and (not mentioning the ID, which is brilliant, permanent) the results are the same on my local env also. |
|
Before merging maybe we could sync with @ypyelab and @TKartist – is it a good idea to fully drop the "simply (ephemeral) numeric id", or could we use it also, putting the "permanent id" into another column? Because ordering by the recent ID does not lead to a readable format in CSV. This new "permanent id" is like this: |
|
It looks good. I believe it would be a good idea to replace the current temp id we have now with the new permanent id considering there are people using the dataset and introducing a new field may cause confusion. Thank you Navin. |
Addresses
Changes
<table-name>-<table-id>Before
After