簡體   English   中英

Django:prefetch_related僅對未分頁的請求授予性能嗎?

[英]Django: prefetch_related grants performance only for non paginated requests?

例如,我有1000個用戶,這些用戶具有在模板中使用的許多相關對象。

這是對的嗎?

User.objects.all()[:10]

總是會比這更好:

User.objects.all().prefetch_related('educations', 'places')[:10]

該行將做一個額外的查詢,以獲取相關的對象用於educationsplaces

User.objects.all().prefetch_related('educations', 'places')[:10]

但是,它只會獲取切片User.objects.all()[:10]的相關對象,因此您不必擔心它將獲取數據庫中成千上萬其他用戶的相關對象。

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM