8
0
Fork 0
mirror of https://gitlab2.federez.net/re2o/re2o synced 2024-11-23 11:53:12 +00:00

Select_related et accélération des vues rest

This commit is contained in:
Gabriel Detraz 2017-05-27 23:54:43 +02:00 committed by root
parent 389487495a
commit 39f3994ec3
4 changed files with 12 additions and 12 deletions

View file

@ -380,7 +380,7 @@ def index_banque(request):
@login_required @login_required
@permission_required('cableur') @permission_required('cableur')
def index(request): def index(request):
facture_list = Facture.objects.order_by('date').reverse() facture_list = Facture.objects.order_by('date').select_related('user').select_related('paiement').prefetch_related('vente_set').reverse()
paginator = Paginator(facture_list, PAGINATION_NUMBER) paginator = Paginator(facture_list, PAGINATION_NUMBER)
page = request.GET.get('page') page = request.GET.get('page')
try: try:

View file

@ -68,7 +68,7 @@ def form(ctx, template, request):
@login_required @login_required
@permission_required('cableur') @permission_required('cableur')
def index(request): def index(request):
revisions = Revision.objects.all().order_by('date_created').reverse() revisions = Revision.objects.all().order_by('date_created').reverse().select_related('user').prefetch_related('version_set__object')
paginator = Paginator(revisions, PAGINATION_NUMBER) paginator = Paginator(revisions, PAGINATION_NUMBER)
page = request.GET.get('page') page = request.GET.get('page')
try: try:

View file

@ -609,7 +609,7 @@ def del_alias(request, interfaceid):
@login_required @login_required
@permission_required('cableur') @permission_required('cableur')
def index(request): def index(request):
machines_list = Machine.objects.order_by('pk') machines_list = Machine.objects.select_related('user').prefetch_related('interface_set__domain__extension').prefetch_related('interface_set__ipv4__ip_type__extension').prefetch_related('interface_set__type').prefetch_related('interface_set__domain__related_domain').order_by('pk')
paginator = Paginator(machines_list, PAGINATION_LARGE_NUMBER) paginator = Paginator(machines_list, PAGINATION_LARGE_NUMBER)
page = request.GET.get('page') page = request.GET.get('page')
try: try:
@ -637,9 +637,9 @@ def index_machinetype(request):
@login_required @login_required
@permission_required('cableur') @permission_required('cableur')
def index_extension(request): def index_extension(request):
extension_list = Extension.objects.order_by('name') extension_list = Extension.objects.select_related('origin').order_by('name')
mx_list = Mx.objects.order_by('zone').select_related('zone') mx_list = Mx.objects.order_by('zone').select_related('zone').select_related('name__extension')
ns_list = Ns.objects.order_by('zone').select_related('zone') ns_list = Ns.objects.order_by('zone').select_related('zone').select_related('ns__extension')
return render(request, 'machines/index_extension.html', {'extension_list':extension_list, 'mx_list': mx_list, 'ns_list': ns_list}) return render(request, 'machines/index_extension.html', {'extension_list':extension_list, 'mx_list': mx_list, 'ns_list': ns_list})
@login_required @login_required
@ -751,7 +751,7 @@ def mac_ip_list(request):
@login_required @login_required
@permission_required('serveur') @permission_required('serveur')
def alias(request): def alias(request):
alias = Domain.objects.filter(interface_parent=None).filter(cname=Domain.objects.filter(interface_parent__in=Interface.objects.exclude(ipv4=None))).select_related('extension') alias = Domain.objects.filter(interface_parent=None).filter(cname=Domain.objects.filter(interface_parent__in=Interface.objects.exclude(ipv4=None))).select_related('extension').select_related('cname__extension')
seria = DomainSerializer(alias, many=True) seria = DomainSerializer(alias, many=True)
return JSONResponse(seria.data) return JSONResponse(seria.data)
@ -759,7 +759,7 @@ def alias(request):
@login_required @login_required
@permission_required('serveur') @permission_required('serveur')
def corresp(request): def corresp(request):
type = IpType.objects.all() type = IpType.objects.all().select_related('extension')
seria = TypeSerializer(type, many=True) seria = TypeSerializer(type, many=True)
return JSONResponse(seria.data) return JSONResponse(seria.data)
@ -767,7 +767,7 @@ def corresp(request):
@login_required @login_required
@permission_required('serveur') @permission_required('serveur')
def mx(request): def mx(request):
mx = Mx.objects.all() mx = Mx.objects.all().select_related('zone').select_related('name__extension')
seria = MxSerializer(mx, many=True) seria = MxSerializer(mx, many=True)
return JSONResponse(seria.data) return JSONResponse(seria.data)
@ -775,7 +775,7 @@ def mx(request):
@login_required @login_required
@permission_required('serveur') @permission_required('serveur')
def ns(request): def ns(request):
ns = Ns.objects.exclude(ns__in=Domain.objects.filter(interface_parent__in=Interface.objects.filter(ipv4=None))) ns = Ns.objects.exclude(ns__in=Domain.objects.filter(interface_parent__in=Interface.objects.filter(ipv4=None))).select_related('zone').select_related('ns__extension')
seria = NsSerializer(ns, many=True) seria = NsSerializer(ns, many=True)
return JSONResponse(seria.data) return JSONResponse(seria.data)
@ -783,7 +783,7 @@ def ns(request):
@login_required @login_required
@permission_required('serveur') @permission_required('serveur')
def zones(request): def zones(request):
zones = Extension.objects.all() zones = Extension.objects.all().select_related('origin')
seria = ExtensionSerializer(zones, many=True) seria = ExtensionSerializer(zones, many=True)
return JSONResponse(seria.data) return JSONResponse(seria.data)

View file

@ -479,7 +479,7 @@ def mass_archive(request):
@permission_required('cableur') @permission_required('cableur')
def index(request): def index(request):
""" Affiche l'ensemble des users, need droit cableur """ """ Affiche l'ensemble des users, need droit cableur """
users_list = User.objects.order_by('state', 'name') users_list = User.objects.select_related('room').order_by('state', 'name')
paginator = Paginator(users_list, PAGINATION_NUMBER) paginator = Paginator(users_list, PAGINATION_NUMBER)
page = request.GET.get('page') page = request.GET.get('page')
try: try: