From 761b0ed5d7ae7418cfac9bf2b12520148ecd559b Mon Sep 17 00:00:00 2001 From: Gabriel Detraz Date: Sat, 27 May 2017 01:40:22 +0200 Subject: [PATCH] =?UTF-8?q?Optimisation=20des=20requ=C3=A8tes=20sql=20pour?= =?UTF-8?q?=20r=C3=A9cup=C3=A9rer=20l'ensemble=20des=20machines=20(divise?= =?UTF-8?q?=20le=20temps=20de=20traitement=20par=2010...)?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- machines/models.py | 1 - machines/views.py | 15 ++++++++++----- 2 files changed, 10 insertions(+), 6 deletions(-) diff --git a/machines/models.py b/machines/models.py index cf3baf88..6ff6bd6d 100644 --- a/machines/models.py +++ b/machines/models.py @@ -31,7 +31,6 @@ from django.utils.functional import cached_property from re2o.settings import MAIN_EXTENSION - class Machine(models.Model): PRETTY_NAME = "Machine" diff --git a/machines/views.py b/machines/views.py index 8957800b..6e268e9a 100644 --- a/machines/views.py +++ b/machines/views.py @@ -47,6 +47,7 @@ from .forms import NewMachineForm, EditMachineForm, EditInterfaceForm, AddInterf from .forms import IpTypeForm, DelIpTypeForm, AliasForm, DelAliasForm, NsForm, DelNsForm, MxForm, DelMxForm from .models import IpType, Machine, Interface, IpList, MachineType, Extension, Mx, Ns, Domain from users.models import User +from users.models import all_has_access from re2o.settings import PAGINATION_NUMBER, PAGINATION_LARGE_NUMBER, MAX_INTERFACES, MAX_ALIAS def full_domain_validator(request, domain): @@ -63,6 +64,14 @@ def full_domain_validator(request, domain): return False return True +def all_active_interfaces(): + """Renvoie l'ensemble des machines autorisées à sortir sur internet """ + return Interface.objects.filter(machine__in=Machine.objects.filter(user__in=all_has_access()).filter(active=True)).select_related('domain').select_related('machine').select_related('type').select_related('ipv4').select_related('domain__extension').select_related('ipv4__ip_type').distinct() + +def all_active_assigned_interfaces(): + """ Renvoie l'ensemble des machines qui ont une ipv4 assignées et disposant de l'accès internet""" + return all_active_interfaces().filter(ipv4__isnull=False) + def unassign_ips(user): machines = user.user_interfaces() for machine in machines: @@ -726,11 +735,7 @@ class JSONResponse(HttpResponse): @login_required @permission_required('serveur') def mac_ip_list(request): - interf = Interface.objects.select_related('ipv4').select_related('domain__extension').all() - interfaces = list(filter( - lambda interface: interface.ipv4 and interface.is_active, - interf - )) + interfaces = all_active_assigned_interfaces() seria = InterfaceSerializer(interfaces, many=True) return seria.data