Hi Vaibhav,

Andréas is right. You need to evaluate the queryset first as the orm
queries are lazy.
So the solution would be something like below example.


another_list = []
getdata = data.objects.all() # this is a queryset

# apply filters if you need to

getdata = list(getdata) # this would be a list in python

for item in getdata: # won't hit database again
if item in another_list:
# do something
pass



Regards,
Chetan Ganji
+91-900-483-4183
ganji.che...@gmail.com
http://ryucoder.in


On Wed, Mar 13, 2019 at 7:27 PM Andréas Kühne <andreas.ku...@hypercode.se>
wrote:

> Hi,
>
> You can't. The way that you are working - it would always go back to the
> database - because you are using the filter methods.
>
> You would need to create a list from the items, then do the comparison in
> python - which probably will be slower (but not necessarily).
>
> Regards,
>
> Andréas
>
>
> Den ons 13 mars 2019 kl 12:44 skrev Vaibhav Mishra <mevaib...@gmail.com>:
>
>> Hi All,
>>
>> I have a table of over 100,000 rows which I need to compare with another
>> list to find if the entry matching a rows is in there or not
>>
>> The following does not work
>>
>> getdata = data.objects.all()
>>
>>
>> mydata= getdata.filter(mycriteria)
>>
>>
>>
>>
>> Process information and comparision from 'mydata'
>>
>>
>>
>> .The code .should fetch all data and should no longer go to Database. ,
>> but it still seem to hit database
>> .
>> Whenever I am running code, I see that for each comparision , the Code is
>> Hitting the database resulting in over thousands of queries and lot of
>> delay in finishing Processing data.
>>
>> How can I force All Data to be stored in RAM so that its no longer needed
>> to access database. ?
>>
>> --
>> You received this message because you are subscribed to the Google Groups
>> "Django users" group.
>> To unsubscribe from this group and stop receiving emails from it, send an
>> email to django-users+unsubscr...@googlegroups.com.
>> To post to this group, send email to django-users@googlegroups.com.
>> Visit this group at https://groups.google.com/group/django-users.
>> To view this discussion on the web visit
>> https://groups.google.com/d/msgid/django-users/a120e643-936e-4f6a-9662-7811808fa8cf%40googlegroups.com
>> <https://groups.google.com/d/msgid/django-users/a120e643-936e-4f6a-9662-7811808fa8cf%40googlegroups.com?utm_medium=email&utm_source=footer>
>> .
>> For more options, visit https://groups.google.com/d/optout.
>>
> --
> You received this message because you are subscribed to the Google Groups
> "Django users" group.
> To unsubscribe from this group and stop receiving emails from it, send an
> email to django-users+unsubscr...@googlegroups.com.
> To post to this group, send email to django-users@googlegroups.com.
> Visit this group at https://groups.google.com/group/django-users.
> To view this discussion on the web visit
> https://groups.google.com/d/msgid/django-users/CAK4qSCevkAVGFf%3DMrS8VVsv2BgPuDkRUqW_tSFwk1dfrzb7pvg%40mail.gmail.com
> <https://groups.google.com/d/msgid/django-users/CAK4qSCevkAVGFf%3DMrS8VVsv2BgPuDkRUqW_tSFwk1dfrzb7pvg%40mail.gmail.com?utm_medium=email&utm_source=footer>
> .
> For more options, visit https://groups.google.com/d/optout.
>

-- 
You received this message because you are subscribed to the Google Groups 
"Django users" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to django-users+unsubscr...@googlegroups.com.
To post to this group, send email to django-users@googlegroups.com.
Visit this group at https://groups.google.com/group/django-users.
To view this discussion on the web visit 
https://groups.google.com/d/msgid/django-users/CAMKMUjs%3DxtJPN-gmnfmg7M%3DSGsP0jg5qru6o%3DcQGJmuqabckkA%40mail.gmail.com.
For more options, visit https://groups.google.com/d/optout.

Reply via email to