mirror of
https://gitlab2.federez.net/re2o/re2o
synced 2024-11-30 08:32:26 +00:00
DNS endpoint SQL optimization
This commit is contained in:
parent
67b492b17d
commit
a9cfc9aebc
3 changed files with 22 additions and 5 deletions
|
@ -701,10 +701,11 @@ class CNAMERecordSerializer(serializers.ModelSerializer):
|
|||
"""
|
||||
alias = serializers.CharField(source='cname.name', read_only=True)
|
||||
hostname = serializers.CharField(source='name', read_only=True)
|
||||
extension = serializers.CharField(source='extension.name', read_only=True)
|
||||
|
||||
class Meta:
|
||||
model = machines.Domain
|
||||
fields = ('alias', 'hostname')
|
||||
fields = ('alias', 'hostname', 'extension')
|
||||
|
||||
|
||||
class DNSZonesSerializer(serializers.ModelSerializer):
|
||||
|
|
|
@ -491,7 +491,14 @@ class DNSZonesView(generics.ListAPIView):
|
|||
"""Exposes the detailed information about each extension (hostnames,
|
||||
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
|
||||
|
||||
|
||||
|
|
|
@ -563,13 +563,22 @@ class Extension(RevMixin, AclMixin, models.Model):
|
|||
return entry
|
||||
|
||||
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):
|
||||
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):
|
||||
return Domain.objects.filter(extension=self).filter(cname__isnull=False)
|
||||
return (Domain.objects
|
||||
.filter(extension=self)
|
||||
.filter(cname__isnull=False)
|
||||
.prefetch_related('cname'))
|
||||
|
||||
@staticmethod
|
||||
def can_use_all(user_request, *_args, **_kwargs):
|
||||
|
|
Loading…
Reference in a new issue