From 796ebf7210949d0ac9157c4e067c53a24a0d6a1d Mon Sep 17 00:00:00 2001 From: Julien Duponchelle Date: Tue, 16 Aug 2016 19:41:59 +0200 Subject: [PATCH] Optimize project closing by avoiding closing unused modules Fix #627 --- gns3server/compute/base_manager.py | 7 +++++++ gns3server/compute/project.py | 14 ++++++++++++-- 2 files changed, 19 insertions(+), 2 deletions(-) diff --git a/gns3server/compute/base_manager.py b/gns3server/compute/base_manager.py index ba9d97b0..bbce4088 100644 --- a/gns3server/compute/base_manager.py +++ b/gns3server/compute/base_manager.py @@ -58,6 +58,13 @@ class BaseManager: self._port_manager = None self._config = Config.instance() + @property + def nodes(self): + """ + List of nodes manage by the module + """ + return self._nodes.values() + @classmethod def instance(cls): """ diff --git a/gns3server/compute/project.py b/gns3server/compute/project.py index 8bfa844f..52fca5b8 100644 --- a/gns3server/compute/project.py +++ b/gns3server/compute/project.py @@ -278,11 +278,21 @@ class Project: Closes the project, but keep information on disk """ + project_nodes_id = set([n.id for n in self.nodes]) + for module in self.compute(): - yield from module.instance().project_closing(self) + module_nodes_id = set([n.id for n in module.instance().nodes]) + # We close the project only for the modules using it + if len(module_nodes_id & project_nodes_id): + yield from module.instance().project_closing(self) + yield from self._close_and_clean(False) + for module in self.compute(): - yield from module.instance().project_closed(self) + module_nodes_id = set([n.id for n in module.instance().nodes]) + # We close the project only for the modules using it + if len(module_nodes_id & project_nodes_id): + yield from module.instance().project_closed(self) try: if os.path.exists(self.tmp_working_directory()):