WIP commit, added caches, found place which is n*n

This commit is contained in:
Shay Nehmad 2019-09-22 19:59:58 +03:00
parent 8c69cc0af9
commit bea41409d5
3 changed files with 13 additions and 1 deletions

View File

@ -122,6 +122,7 @@ class ReportService:
formatted_nodes = []
# TODO Figure out and improve
nodes = \
[NodeService.get_displayed_node_by_id(node['_id'], True) for node in mongo.db.node.find({}, {'_id': 1})] \
+ [NodeService.get_displayed_node_by_id(monkey['_id'], True) for monkey in

View File

@ -7,6 +7,11 @@ import struct
import ipaddress
from netifaces import interfaces, ifaddresses, AF_INET
try:
from functools import lru_cache
except ImportError:
from backports.functools_lru_cache import lru_cache
__author__ = 'Barak'
@ -46,9 +51,13 @@ else:
# name of interface is (namestr[i:i+16].split('\0', 1)[0]
finally:
return result
# End of local ips function
# The local IP addresses list should not change often. Therefore, we can cache the result and never call this function
# more than once. This stopgap measure is here since this function is called a lot of times during the report
# generation.
# This means that if the interfaces of the Island machines change, the Island process needs to be restarted.
@lru_cache(maxsize=1)
def local_ip_addresses():
ip_list = []
for interface in interfaces():
@ -57,6 +66,7 @@ def local_ip_addresses():
return ip_list
@lru_cache(maxsize=1)
def get_subnets():
subnets = []
for interface in interfaces():

View File

@ -26,3 +26,4 @@ mongoengine
mongomock
requests
dpath
backports