graphql-python / graphql-python/swapi-graphene

Querying for allSpecies and homeworld executes 38 SQL queries

オープン
#12 コメント 7 件 リアクション 0 件 担当者 0 名 GitHub で見る
主要言語
Python
スター
174
フォーク
33
PR マージ指標
30日以内にマージされた PR はありません

説明

This query:

{
allSpecies {
edges {
node {
name
homeworld {
name
gravity
}
}
}
}
}

Executes 38 sql queries, looking something like this:

(0.001) SELECT COUNT(*) AS "__count" FROM "starwars_species"; args=()
(0.000) SELECT "starwars_species"."id", "starwars_species"."created",
"starwars_species"."edited", "starwars_species"."name",
"starwars_species"."classification", "starwars_species"."designation",
"starwars_species"."average_height", "starwars_species"."skin_colors",
"starwars_species"."hair_colors", "starwars_species"."eye_colors",
"starwars_species"."average_lifespan", "starwars_species"."homeworld_id",
"starwars_species"."language" FROM "starwars_species" LIMIT 37; args=()

(0.000) SELECT "starwars_planet"."id", "starwars_planet"."created",
"starwars_planet"."edited", "starwars_planet"."name",
"starwars_planet"."rotation_period", "starwars_planet"."orbital_period",
"starwars_planet"."diameter", "starwars_planet"."climate",
"starwars_planet"."gravity", "starwars_planet"."terrain",
"starwars_planet"."surface_water", "starwars_planet"."population" FROM
"starwars_planet" WHERE "starwars_planet"."id" = 9; args=(9,)

(0.000) SELECT "starwars_planet"."id", "starwars_planet"."created",
"starwars_planet"."edited", "starwars_planet"."name",
"starwars_planet"."rotation_period", "starwars_planet"."orbital_period",
"starwars_planet"."diameter", "starwars_planet"."climate",
"starwars_planet"."gravity", "starwars_planet"."terrain",
"starwars_planet"."surface_water", "starwars_planet"."population" FROM
"starwars_planet" WHERE "starwars_planet"."id" = 14; args=(14,)

... repeat another 36 times

Full list here: https://gist.github.com/simonw/762a98de85a2f113d1d7ec6026f73ee4

Is it possible to detect this case and then use select_related() or prefetch_related() here to join against the relevant table and get everything done in just one or two queries?

If so, an example showing how to do that would be a fantastic illustration of a slightly more complex use-case for graphene-django (I tried myself and couldn't figure out how to do it).

コントリビューションガイド

このリポジトリのコントリビューションガイドは索引されていません

評価

この issue はまだ評価されていません。

新しい issue をメールで受け取る

初心者向けの GitHub issue を短くまとめたダイジェスト。