mirror of
https://gitlab2.federez.net/re2o/re2o
synced 2024-12-26 00:43:46 +00:00
Optimisation des requètes sql pour récupérer l'ensemble des machines (divise le temps de traitement par 10...)
This commit is contained in:
parent
67ac11f8f9
commit
e27b40dbe3
2 changed files with 10 additions and 6 deletions
|
@ -31,7 +31,6 @@ from django.utils.functional import cached_property
|
|||
|
||||
from re2o.settings import MAIN_EXTENSION
|
||||
|
||||
|
||||
class Machine(models.Model):
|
||||
PRETTY_NAME = "Machine"
|
||||
|
||||
|
|
|
@ -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
|
||||
|
||||
|
|
Loading…
Reference in a new issue