Commit a9cfc9ae authored by Maël Kervella's avatar Maël Kervella

DNS endpoint SQL optimization

parent 67b492b1
...@@ -701,10 +701,11 @@ class CNAMERecordSerializer(serializers.ModelSerializer): ...@@ -701,10 +701,11 @@ class CNAMERecordSerializer(serializers.ModelSerializer):
""" """
alias = serializers.CharField(source='cname.name', read_only=True) alias = serializers.CharField(source='cname.name', read_only=True)
hostname = serializers.CharField(source='name', read_only=True) hostname = serializers.CharField(source='name', read_only=True)
extension = serializers.CharField(source='extension.name', read_only=True)
class Meta: class Meta:
model = machines.Domain model = machines.Domain
fields = ('alias', 'hostname') fields = ('alias', 'hostname', 'extension')
class DNSZonesSerializer(serializers.ModelSerializer): class DNSZonesSerializer(serializers.ModelSerializer):
......
...@@ -491,7 +491,14 @@ class DNSZonesView(generics.ListAPIView): ...@@ -491,7 +491,14 @@ class DNSZonesView(generics.ListAPIView):
"""Exposes the detailed information about each extension (hostnames, """Exposes the detailed information about each extension (hostnames,
IPs, DNS records, etc.) in order to build the DNS zone files. IPs, DNS records, etc.) in order to build the DNS zone files.
""" """
queryset = machines.Extension.objects.all() queryset = (machines.Extension.objects
.prefetch_related('soa')
.prefetch_related('ns_set').prefetch_related('ns_set__ns')
.prefetch_related('origin')
.prefetch_related('mx_set').prefetch_related('mx_set__name')
.prefetch_related('txt_set')
.prefetch_related('srv_set').prefetch_related('srv_set__target')
.all())
serializer_class = serializers.DNSZonesSerializer serializer_class = serializers.DNSZonesSerializer
......
...@@ -563,13 +563,22 @@ class Extension(RevMixin, AclMixin, models.Model): ...@@ -563,13 +563,22 @@ class Extension(RevMixin, AclMixin, models.Model):
return entry return entry
def get_associated_a_records(self): def get_associated_a_records(self):
return Interface.objects.filter(type__ip_type__extension=self).filter(ipv4__isnull=False) return (Interface.objects
.filter(type__ip_type__extension=self)
.filter(ipv4__isnull=False)
.prefetch_related('domain')
.prefetch_related('ipv4'))
def get_associated_aaaa_records(self): def get_associated_aaaa_records(self):
return Interface.objects.filter(type__ip_type__extension=self) return (Interface.objects
.filter(type__ip_type__extension=self)
.prefetch_related('domain'))
def get_associated_cname_records(self): def get_associated_cname_records(self):
return Domain.objects.filter(extension=self).filter(cname__isnull=False) return (Domain.objects
.filter(extension=self)
.filter(cname__isnull=False)
.prefetch_related('cname'))
@staticmethod @staticmethod
def can_use_all(user_request, *_args, **_kwargs): def can_use_all(user_request, *_args, **_kwargs):
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment