v1k45 / django-notify-x

Notification system for Django
MIT License
187 stars 40 forks source link

Queries using prefetch_relations are not lazy #28

Closed fgmacedo closed 8 years ago

fgmacedo commented 8 years ago

Hi, I've found that prefetch_relations evaluates all queries, not alowing cascading further filters.

So, the following query will retrive all notifications from DB:

Notification.objects.active().filter(nf_type='my_type')

I think that we should remove the implicit call to prefetch_relations from the NotificationQueryset, and add a new queryset method like prefetch, to be explicit called when the context needs it. With a note that prefetch is not lazy.

The above example can be fixed using:

pretetch_relations(Notification.objects.filter(nf_type='badge_awarded'))

Or if we implement pretetch as a isolated queryset method:

Notification.objects.filter(nf_type='badge_awarded').prefetch()

What do you think?

v1k45 commented 8 years ago

prefetch as a queryset method looks more clean to me. Are you already working on it?

fgmacedo commented 8 years ago

Ok. Not yet. But it's something that I will need, so expect it to the next few days.