-
Notifications
You must be signed in to change notification settings - Fork 430
Open
Description
In a DetailView I configure the queryset directly in the class, like this:
class ProtocolDetailView(
PermissionRequiredMixin, LogAccessMixin, LoginRequiredMixin, DetailView
):
queryset = (
Protocol.objects.select_related(
"related_protocol",
"department",
"sub_department",
"status_protocol",
"created_by",
)
.prefetch_related(
"status_protocol__history_status_protocol__doer",
"status_protocol__history_status_protocol__department",
"status_protocol__history_status_protocol__sub_department",
"related_protocols__status_protocol",
"status_protocol__history_logs__actor",
)
.all()
)
template_name = "management/protocols/detail.html"
permission_required = ("management.view_protocol",)
model = Protocol
Yes, a large search is done. Through the LogAccessMixin
Mixin, the get_object
method is called in the render_to_response
method. I noticed that this causes duplicate calls in the database, that is, the get_object
method has already been called previously.
The number of calls made to the bank with Mixin
Now I remove the Mixin and implement the render_to_response
method in a similar way but fetching the value of self.object
first.
def render_to_response(self, context, **response_kwargs):
obj = self.get_object() if self.object is None else self.object
accessed.send(obj.__class__, instance=obj)
return super().render_to_response(context, **response_kwargs)
I know the numbers are low, but on a larger scale it will be possible to avoid large numbers of consultations.
Metadata
Metadata
Assignees
Labels
No labels