mirror of
https://github.com/netbox-community/netbox.git
synced 2025-07-15 19:52:52 -06:00
Improved device interface list performance
This commit is contained in:
parent
5716207ba6
commit
e647065e63
@ -382,7 +382,7 @@ class InterfaceNestedSerializer(InterfaceSerializer):
|
|||||||
|
|
||||||
|
|
||||||
class InterfaceDetailSerializer(InterfaceSerializer):
|
class InterfaceDetailSerializer(InterfaceSerializer):
|
||||||
connected_interface = InterfaceSerializer(source='get_connected_interface')
|
connected_interface = InterfaceSerializer()
|
||||||
|
|
||||||
class Meta(InterfaceSerializer.Meta):
|
class Meta(InterfaceSerializer.Meta):
|
||||||
fields = ['id', 'device', 'name', 'form_factor', 'mac_address', 'mgmt_only', 'description', 'is_connected',
|
fields = ['id', 'device', 'name', 'form_factor', 'mac_address', 'mgmt_only', 'description', 'is_connected',
|
||||||
|
@ -455,7 +455,7 @@ class RelatedConnectionsView(APIView):
|
|||||||
peer_iface = Interface.objects.get(device__name=peer_device, name=peer_interface)
|
peer_iface = Interface.objects.get(device__name=peer_device, name=peer_interface)
|
||||||
except Interface.DoesNotExist:
|
except Interface.DoesNotExist:
|
||||||
raise Http404()
|
raise Http404()
|
||||||
local_iface = peer_iface.get_connected_interface()
|
local_iface = peer_iface.connected_interface
|
||||||
if local_iface:
|
if local_iface:
|
||||||
device = local_iface.device
|
device = local_iface.device
|
||||||
else:
|
else:
|
||||||
|
@ -1156,13 +1156,18 @@ class Interface(models.Model):
|
|||||||
pass
|
pass
|
||||||
return None
|
return None
|
||||||
|
|
||||||
def get_connected_interface(self):
|
@property
|
||||||
connection = InterfaceConnection.objects.select_related().filter(Q(interface_a=self) | Q(interface_b=self))\
|
def connected_interface(self):
|
||||||
.first()
|
try:
|
||||||
if connection and connection.interface_a == self:
|
if self.connected_as_a:
|
||||||
return connection.interface_b
|
return self.connected_as_a.interface_b
|
||||||
elif connection:
|
except ObjectDoesNotExist:
|
||||||
return connection.interface_a
|
pass
|
||||||
|
try:
|
||||||
|
if self.connected_as_b:
|
||||||
|
return self.connected_as_b.interface_a
|
||||||
|
except ObjectDoesNotExist:
|
||||||
|
pass
|
||||||
return None
|
return None
|
||||||
|
|
||||||
|
|
||||||
|
@ -597,10 +597,16 @@ def device(request, pk):
|
|||||||
power_outlets = natsorted(
|
power_outlets = natsorted(
|
||||||
PowerOutlet.objects.filter(device=device).select_related('connected_port'), key=attrgetter('name')
|
PowerOutlet.objects.filter(device=device).select_related('connected_port'), key=attrgetter('name')
|
||||||
)
|
)
|
||||||
interfaces = Interface.objects.filter(device=device, mgmt_only=False)\
|
interfaces = Interface.objects.filter(device=device, mgmt_only=False).select_related(
|
||||||
.select_related('connected_as_a', 'connected_as_b', 'circuit_termination__circuit')
|
'connected_as_a__interface_b__device',
|
||||||
mgmt_interfaces = Interface.objects.filter(device=device, mgmt_only=True)\
|
'connected_as_b__interface_a__device',
|
||||||
.select_related('connected_as_a', 'connected_as_b', 'circuit_termination__circuit')
|
'circuit_termination__circuit',
|
||||||
|
)
|
||||||
|
mgmt_interfaces = Interface.objects.filter(device=device, mgmt_only=True).select_related(
|
||||||
|
'connected_as_a__interface_b__device',
|
||||||
|
'connected_as_b__interface_a__device',
|
||||||
|
'circuit_termination__circuit',
|
||||||
|
)
|
||||||
device_bays = natsorted(
|
device_bays = natsorted(
|
||||||
DeviceBay.objects.filter(device=device).select_related('installed_device__device_type__manufacturer'),
|
DeviceBay.objects.filter(device=device).select_related('installed_device__device_type__manufacturer'),
|
||||||
key=attrgetter('name')
|
key=attrgetter('name')
|
||||||
|
@ -23,7 +23,7 @@
|
|||||||
<tr id="{{ iface }}">
|
<tr id="{{ iface }}">
|
||||||
<td>{{ iface }}</td>
|
<td>{{ iface }}</td>
|
||||||
{% if iface.connection %}
|
{% if iface.connection %}
|
||||||
{% with iface.get_connected_interface as connected_iface %}
|
{% with iface.connected_interface as connected_iface %}
|
||||||
<td class="configured_device" data="{{ connected_iface.device }}">
|
<td class="configured_device" data="{{ connected_iface.device }}">
|
||||||
<a href="{% url 'dcim:device' pk=connected_iface.device.pk %}">{{ connected_iface.device }}</a>
|
<a href="{% url 'dcim:device' pk=connected_iface.device.pk %}">{{ connected_iface.device }}</a>
|
||||||
</td>
|
</td>
|
||||||
|
@ -16,7 +16,7 @@
|
|||||||
{% if not iface.is_physical %}
|
{% if not iface.is_physical %}
|
||||||
<td colspan="2" class="text-muted">Virtual interface</td>
|
<td colspan="2" class="text-muted">Virtual interface</td>
|
||||||
{% elif iface.connection %}
|
{% elif iface.connection %}
|
||||||
{% with iface.get_connected_interface as connected_iface %}
|
{% with iface.connected_interface as connected_iface %}
|
||||||
<td>
|
<td>
|
||||||
<a href="{% url 'dcim:device' pk=connected_iface.device.pk %}">{{ connected_iface.device }}</a>
|
<a href="{% url 'dcim:device' pk=connected_iface.device.pk %}">{{ connected_iface.device }}</a>
|
||||||
</td>
|
</td>
|
||||||
@ -27,7 +27,7 @@
|
|||||||
{% elif iface.circuit_termination %}
|
{% elif iface.circuit_termination %}
|
||||||
{% with iface.circuit_termination.get_peer_termination as peer_termination %}
|
{% with iface.circuit_termination.get_peer_termination as peer_termination %}
|
||||||
<td colspan="2">
|
<td colspan="2">
|
||||||
<i class="fa fa-fw fa-globe"></i>
|
<i class="fa fa-fw fa-globe" title="Circuit"></i>
|
||||||
{% if peer_termination %}
|
{% if peer_termination %}
|
||||||
<a href="{% url 'dcim:site' slug=peer_termination.site.slug %}">{{ peer_termination.site }}</a> via
|
<a href="{% url 'dcim:site' slug=peer_termination.site.slug %}">{{ peer_termination.site }}</a> via
|
||||||
{% endif %}
|
{% endif %}
|
||||||
|
Loading…
Reference in New Issue
Block a user