Django:迭代一个没有缓存的查询集 [英] Django : Iterate over a query set without cache
本文介绍了Django:迭代一个没有缓存的查询集的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我有一个愚蠢的简单循环
I have a dumb simple loop
for alias in models.Alias.objects.all() :
alias.update_points()
但是查看django QuerySet它似乎保持在$ code> _result_cache 所有以前的结果。这正在吃我的机器的Gigs和Gigs,最终一切都爆了。
but looking into the django QuerySet it seems to keep around a _result_cache
of all the previous results. This is eating Gigs and Gigs of my machine and eventually everything blows up.
如何扔掉我不会关心的所有东西?
How can I throw away all the stuff that I won't ever care about?
推荐答案
使用查询集的 迭代器()
方法返回模块,而不填充结果缓存:
Use the queryset's iterator()
method to return the models in chunks, without populating the result cache:
for alias in models.Alias.objects.iterator() :
alias.update_points()
这篇关于Django:迭代一个没有缓存的查询集的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文