Fix #7365: Optimize calculation of prefix utilization

This commit is contained in:
Shuichiro MAKIGAKI 2021-09-22 12:49:34 +09:00
parent 38172b793b
commit d514290688

View File

@ -487,11 +487,9 @@ class Prefix(PrimaryModel):
utilization = int(float(child_prefixes.size) / self.prefix.size * 100)
else:
# Compile an IPSet to avoid counting duplicate IPs
child_ips = netaddr.IPSet()
for iprange in self.get_child_ranges():
child_ips.add(iprange.range)
for ip in self.get_child_ips():
child_ips.add(ip.address.ip)
child_ips = netaddr.IPSet(
[_.range for _ in self.get_child_ranges()] + [_.address.ip for _ in self.get_child_ips()]
)
prefix_size = self.prefix.size
if self.prefix.version == 4 and self.prefix.prefixlen < 31 and not self.is_pool: