From 7afd4464383041c745c81a2297be4a547e3f8e17 Mon Sep 17 00:00:00 2001 From: Gabriel Detraz Date: Thu, 2 Feb 2017 02:21:39 +0100 Subject: [PATCH] Optimisation --- machines/views.py | 18 +++++++++--------- 1 file changed, 9 insertions(+), 9 deletions(-) diff --git a/machines/views.py b/machines/views.py index 4609be86..81fe11c6 100644 --- a/machines/views.py +++ b/machines/views.py @@ -725,13 +725,13 @@ class JSONResponse(HttpResponse): @csrf_exempt @login_required @permission_required('serveur') -def interface_list(request): - interfaces = Interface.objects.all() - interface = [] - for i in interfaces : - if i.ipv4 and i.is_active(): - interface.append(i) - seria = InterfaceSerializer(interface, many=True) +def mac_ip_list(request): + interfaces = Interface.objects.select_related('ipv4').select_related('domain').all() + filter( + lambda interface: interface.ipv4 and interface.is_active(), + interfaces + ) + seria = InterfaceSerializer(interfaces, many=True) return seria.data @csrf_exempt @@ -778,14 +778,14 @@ def zones(request): @login_required @permission_required('serveur') def mac_ip(request): - seria = interface_list(request) + seria = mac_ip_list(request) return JSONResponse(seria) @csrf_exempt @login_required @permission_required('serveur') def mac_ip_dns(request): - seria = interface_list(request) + seria = mac_ip_list(request) return JSONResponse(seria) @csrf_exempt