Mani Shirvani
Mani Shirvani

Reputation: 328

Django - data too large for session

I have a view in which I query the database then I give the queryset to session and use it in other views. It works fine most of the time but in vary rare cases when the queryset gets very large, it takes a long time and I get a timeout. What I would like to know is if I am doing the right thing? If not, what is the best practice for this case? What options do I have?

Upvotes: 0

Views: 336

Answers (1)

Vadim Karpenko
Vadim Karpenko

Reputation: 52

I never store QuerySet data in sessions. You need just to make a list (like [1,2,3,4,5]) of all id's you need, then send it.

Next step it is to get QuerySet from list of id's:

data_list = request.session['data_list']
services = Service.objects.filter(id__in=data_list)

and now you have same QuerySet you have before, but sessions never be filled.

Upvotes: 1

Related Questions