-
Notifications
You must be signed in to change notification settings - Fork 7
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Add option to enable globally #131
Comments
It's an interesting idea. In the 7 or 8 years since we initially wrote this I've never imposed it on third party packages, but I don't see any concern doing that and there is already an open ticket for merging it into Django proper. I'm not sure how hard it will be to support across different versions of Django or how much code could be shared with the current version. |
I believe it would be sufficient to have a model.py with the following content: from django.db import models
import auto_prefetch
models.ForeignKey.forward_related_accessor_class = auto_prefetch.ForwardManyToOneDescriptor
models.OneToOneField.forward_related_accessor_class = auto_prefetch.ForwardOneToOneDescriptor
models.OneToOneField.related_accessor_class = auto_prefetch.ReverseOneToOneDescriptor
models.QuerySet = auto_prefetch.QuerySet Then adding |
This is an interesting idea that I'm curious to try out when I get some time, you could try it yourself, just create a new app that does what you suggest and put it at the top of your INSTALLED_APPS |
Description
As far as I understand, this package aims at preventing common mistakes, especially for developers who are less experienced with the ORM. As such I believe that it is important to have as low a threshold as possible. Ideally it would be "just install this package and everything will be faster".
I imaging this could be achieved by patching the django classes rather than extending them. Of course that would also be a lot less clean. So I was wondering whether it would be possible to have this as an opt-in setting. Something like
USE_GLOBAL_AUTO_PREFETCH = True
.What do you think?
The text was updated successfully, but these errors were encountered: