You seem to be hauling the same data from one side to the other, and I can't see why.
Try: MyModel.objects.values_list('id', flat=True) You can use that to build a dictionary if you add a second field, or using list comprehensions which I believe are faster than for loops, dict(MyModel.objects.values_list('id', 'docid')) but I honestly don't understand what you are trying to do. Maybe if you share more of the model logic and explain what you are trying to achieve we can provide you with a way to get there, instead of trying to improve the way you decided to go about it. Cheers, André Terra On Mon, Jul 11, 2011 at 10:57 AM, Michel30 <forerunn...@gmail.com> wrote: > Hi all, > > I have a basic search function that uses Q objects. > After profiling it I found that the actual (mysql) database query > finishes in fractions of seconds but the iterating after this can take > up to 50 seconds per 10.000 results. > > I have been trying to speed it up but I have had not much results.. > > My query is this one: > > found_entries = model.objects.filter((Q-objects), > obsolete=0).order_by('-version','docid') > > So far so good, but then I need a dictionary to retrieve only unique > 'documentid's'. > > rev_dict = {} > > This is the part that hurts: > > for d in found_entries: > rev_dict[d.documentid] = d > > And then some more sorting and filtering: > > filtered_entries = rev_dict.values() > filtered_entries.sort(key=lambda d: d.revisiondate, reverse=True) > > Does anyone have some better ideas to achieve this? > > Thanks > > -- > You received this message because you are subscribed to the Google Groups > "Django users" group. > To post to this group, send email to django-users@googlegroups.com. > To unsubscribe from this group, send email to > django-users+unsubscr...@googlegroups.com. > For more options, visit this group at > http://groups.google.com/group/django-users?hl=en. > > -- You received this message because you are subscribed to the Google Groups "Django users" group. To post to this group, send email to django-users@googlegroups.com. To unsubscribe from this group, send email to django-users+unsubscr...@googlegroups.com. For more options, visit this group at http://groups.google.com/group/django-users?hl=en.