Optimization: do not create an additional request to get interfaces

This commit is contained in:
Victor Golovanenko 2021-04-26 08:40:06 +00:00
parent 10ccc72c09
commit 0f85c97038
No known key found for this signature in database
GPG Key ID: F3B58DF29DBC2099

View File

@ -17,7 +17,7 @@ class InterfaceComparisonView(LoginRequiredMixin, PermissionRequiredMixin, View)
def get(self, request, device_id): def get(self, request, device_id):
device = get_object_or_404(Device.objects.filter(id=device_id)) device = get_object_or_404(Device.objects.filter(id=device_id))
interfaces = Interface.objects.filter(device=device) interfaces = device.vc_interfaces
if config["exclude_virtual_interfaces"]: if config["exclude_virtual_interfaces"]:
interfaces = list(filter(lambda i: not i.is_virtual, interfaces)) interfaces = list(filter(lambda i: not i.is_virtual, interfaces))
interface_templates = InterfaceTemplate.objects.filter(device_type=device.device_type) interface_templates = InterfaceTemplate.objects.filter(device_type=device.device_type)
@ -58,7 +58,7 @@ class InterfaceComparisonView(LoginRequiredMixin, PermissionRequiredMixin, View)
form = InterfaceComparisonForm(request.POST) form = InterfaceComparisonForm(request.POST)
if form.is_valid(): if form.is_valid():
device = get_object_or_404(Device.objects.filter(id=device_id)) device = get_object_or_404(Device.objects.filter(id=device_id))
interfaces = Interface.objects.filter(device=device) interfaces = device.vc_interfaces
if config["exclude_virtual_interfaces"]: if config["exclude_virtual_interfaces"]:
interfaces = interfaces.exclude(type__in=["virtual", "lag"]) interfaces = interfaces.exclude(type__in=["virtual", "lag"])
interface_templates = InterfaceTemplate.objects.filter(device_type=device.device_type) interface_templates = InterfaceTemplate.objects.filter(device_type=device.device_type)