中文名稱 數據加載器 解決一些重複Query的問題 小至重複三五次 大到重覆幾百次 若是每次都查詢一樣的東西 除了在sql上加上cache以外
也可以將數據蒐集起來再做一次query 避免大量query的窘境
情境: 若是有一個Graphql 需要 user
以及 user'post
當這個例子需要 user list and post list 的時候
user
list 的sql:
select id, name, telephone from user where id in (?,?,?,?,?)
user'post
list sql:
select id, title, content from post where user_id = ?
select id, title, content from post where user_id = ?
select id, title, content from post where user_id = ?
select id, title, content from post where user_id = ?
select id, title, content from post where user_id = ?
就會變成有幾個user做幾次query 看到這裡 你的心裡也會覺得 為何不能將這些ID蒐集起來再做一次query
example
select id, title, content from post where user_id in (?,?,?,?,?)
而dataloader就是為了解決sql效能上的問題而出現的 將需要query的id蒐集
起來