[Fixed]-How to remove Django`s BinaryField from memory?

1๐Ÿ‘

โœ…

Use an iterator like this.

myDataList = MyData.objects().filter(...).defer('data')
for myData in myDataList.iterator():
    doSmthWithData(myData.data)

Evaluates the QuerySet (by performing the query) and returns an iterator (see PEP 234) over the results. A QuerySet typically caches its results internally so that repeated evaluations do not result in additional queries. In contrast, iterator() will read results directly, without doing any caching at the QuerySet level (internally, the default iterator calls iterator() and caches the return value). For a QuerySet which returns a large number of objects that you only need to access once, this can result in better performance and a significant reduction in memory.

๐Ÿ‘คAndruten

Leave a comment