Michael Radziej wrote: > Malcolm Tredinnick schrieb: >> Interestingly, looking at QuerySet.iterator() and QuerySet.__iter__, >> they aren't synonyms. The point is that QuerySet.__iter__ iterates over >> the result of QuerySet._get_data(), which actually sucks everything into >> memory before iterating. On the other hand, QuerySet.iterator() is a >> more memory-conscious thing, iterating over each row at a time, >> returning it as it is retrieved. I'm not sure if this is just an >> accidental implementation issue or something intentional, but it's going >> to make me use iterator() a bit more explicitly in at least one case I >> can think of. Hmm.. the things you learn when you take the time to read >> the source... > > It makes sense (after a while ;-) Usually, you want to build up a > cache and not throw everything away. iterator() neither makes use > of an existing cache nor stores the results. You don't want this > to be the default behaviour. >
hmm.. maybe i am only implementing strange web-applications, but up to now, i never ever needed the caching behaviour of the QuerySets...so i probably will have to ALWAYS use the iterator() method. (just for curiosity... could someone describe me a typical use-case, where caching querysets are important? because my typical views work like : query-objects, do something with-them, render the response. no queryset-reuse there. and if i need to reuse it, i can store it in a list somewhere . (yes, i do realize that this is already decided (that caching should be default). i'm only trying to understand it)...) somehow i assumed that the QuerySets never load in the whole result-set, except when they are forced (cast to list for example). but now i see that of course, if you cache the results, then you will have all the results in memory anyway... so caching and load-all-results are basically the same :-( i personally don't need caching, but could live with it. my problem problem is the load-all-results part :) but as i said, probably always-using the iterator() way will help. btw. is there any difference between the 2 ways? (i assume not, because the __iter__ code basically does a "list(self.iterator())") gabor --~--~---------~--~----~------------~-------~--~----~ You received this message because you are subscribed to the Google Groups "Django developers" group. To post to this group, send email to [email protected] To unsubscribe from this group, send email to [EMAIL PROTECTED] For more options, visit this group at http://groups.google.com/group/django-developers -~----------~----~----~----~------~----~------~--~---
