mirror of
https://github.com/netbox-community/netbox.git
synced 2025-07-15 11:42: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):
|
||||
connected_interface = InterfaceSerializer(source='get_connected_interface')
|
||||
connected_interface = InterfaceSerializer()
|
||||
|
||||
class Meta(InterfaceSerializer.Meta):
|
||||
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)
|
||||
except Interface.DoesNotExist:
|
||||
raise Http404()
|
||||
local_iface = peer_iface.get_connected_interface()
|
||||
local_iface = peer_iface.connected_interface
|
||||
if local_iface:
|
||||
device = local_iface.device
|
||||
else:
|
||||
|
@ -1156,13 +1156,18 @@ class Interface(models.Model):
|
||||
pass
|
||||
return None
|
||||
|
||||
def get_connected_interface(self):
|
||||
connection = InterfaceConnection.objects.select_related().filter(Q(interface_a=self) | Q(interface_b=self))\
|
||||
.first()
|
||||
if connection and connection.interface_a == self:
|
||||
return connection.interface_b
|
||||
elif connection:
|
||||
return connection.interface_a
|
||||
@property
|
||||
def connected_interface(self):
|
||||
try:
|
||||
if self.connected_as_a:
|
||||
return self.connected_as_a.interface_b
|
||||
except ObjectDoesNotExist:
|
||||
pass
|
||||
try:
|
||||
if self.connected_as_b:
|
||||
return self.connected_as_b.interface_a
|
||||
except ObjectDoesNotExist:
|
||||
pass
|
||||
return None
|
||||
|
||||
|
||||
|
@ -597,10 +597,16 @@ def device(request, pk):
|
||||
power_outlets = natsorted(
|
||||
PowerOutlet.objects.filter(device=device).select_related('connected_port'), key=attrgetter('name')
|
||||
)
|
||||
interfaces = Interface.objects.filter(device=device, mgmt_only=False)\
|
||||
.select_related('connected_as_a', 'connected_as_b', 'circuit_termination__circuit')
|
||||
mgmt_interfaces = Interface.objects.filter(device=device, mgmt_only=True)\
|
||||
.select_related('connected_as_a', 'connected_as_b', 'circuit_termination__circuit')
|
||||
interfaces = Interface.objects.filter(device=device, mgmt_only=False).select_related(
|
||||
'connected_as_a__interface_b__device',
|
||||
'connected_as_b__interface_a__device',
|
||||
'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(
|
||||
DeviceBay.objects.filter(device=device).select_related('installed_device__device_type__manufacturer'),
|
||||
key=attrgetter('name')
|
||||
|
@ -23,7 +23,7 @@
|
||||
<tr id="{{ iface }}">
|
||||
<td>{{ iface }}</td>
|
||||
{% 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 }}">
|
||||
<a href="{% url 'dcim:device' pk=connected_iface.device.pk %}">{{ connected_iface.device }}</a>
|
||||
</td>
|
||||
|
@ -16,7 +16,7 @@
|
||||
{% if not iface.is_physical %}
|
||||
<td colspan="2" class="text-muted">Virtual interface</td>
|
||||
{% elif iface.connection %}
|
||||
{% with iface.get_connected_interface as connected_iface %}
|
||||
{% with iface.connected_interface as connected_iface %}
|
||||
<td>
|
||||
<a href="{% url 'dcim:device' pk=connected_iface.device.pk %}">{{ connected_iface.device }}</a>
|
||||
</td>
|
||||
@ -27,7 +27,7 @@
|
||||
{% elif iface.circuit_termination %}
|
||||
{% with iface.circuit_termination.get_peer_termination as peer_termination %}
|
||||
<td colspan="2">
|
||||
<i class="fa fa-fw fa-globe"></i>
|
||||
<i class="fa fa-fw fa-globe" title="Circuit"></i>
|
||||
{% if peer_termination %}
|
||||
<a href="{% url 'dcim:site' slug=peer_termination.site.slug %}">{{ peer_termination.site }}</a> via
|
||||
{% endif %}
|
||||
|
Loading…
Reference in New Issue
Block a user