1
0
mirror of https://github.com/GNS3/gns3-server synced 2024-11-24 17:28:08 +00:00

Improve a lot project loading speed

Fix #893
This commit is contained in:
Julien Duponchelle 2017-02-06 11:40:00 +01:00
parent fbe26d11cf
commit 0d7157c295
No known key found for this signature in database
GPG Key ID: CE8B29639E07F5E8
2 changed files with 22 additions and 11 deletions

View File

@ -52,9 +52,11 @@ class Link:
return self._created return self._created
@asyncio.coroutine @asyncio.coroutine
def add_node(self, node, adapter_number, port_number, label=None): def add_node(self, node, adapter_number, port_number, label=None, dump=True):
""" """
Add a node to the link Add a node to the link
:param dump: Dump project on disk
""" """
port = node.get_port(adapter_number, port_number) port = node.get_port(adapter_number, port_number)
@ -101,7 +103,8 @@ class Link:
self._created = True self._created = True
self._project.controller.notification.emit("link.created", self.__json__()) self._project.controller.notification.emit("link.created", self.__json__())
self._project.dump() if dump:
self._project.dump()
@asyncio.coroutine @asyncio.coroutine
def update_nodes(self, nodes): def update_nodes(self, nodes):

View File

@ -314,10 +314,11 @@ class Project:
@open_required @open_required
@asyncio.coroutine @asyncio.coroutine
def add_node(self, compute, name, node_id, node_type=None, **kwargs): def add_node(self, compute, name, node_id, dump=True, node_type=None, **kwargs):
""" """
Create a node or return an existing node Create a node or return an existing node
:param dump: Dump topology to disk
:param kwargs: See the documentation of node :param kwargs: See the documentation of node
""" """
if node_id in self._nodes: if node_id in self._nodes:
@ -349,7 +350,8 @@ class Project:
yield from node.create() yield from node.create()
self._nodes[node.id] = node self._nodes[node.id] = node
self.controller.notification.emit("node.created", node.__json__()) self.controller.notification.emit("node.created", node.__json__())
self.dump() if dump:
self.dump()
return node return node
@locked_coroutine @locked_coroutine
@ -401,17 +403,19 @@ class Project:
@open_required @open_required
@asyncio.coroutine @asyncio.coroutine
def add_drawing(self, drawing_id=None, **kwargs): def add_drawing(self, drawing_id=None, dump=True, **kwargs):
""" """
Create an drawing or return an existing drawing Create an drawing or return an existing drawing
:param dump: Dump the topology to disk
:param kwargs: See the documentation of drawing :param kwargs: See the documentation of drawing
""" """
if drawing_id not in self._drawings: if drawing_id not in self._drawings:
drawing = Drawing(self, drawing_id=drawing_id, **kwargs) drawing = Drawing(self, drawing_id=drawing_id, **kwargs)
self._drawings[drawing.id] = drawing self._drawings[drawing.id] = drawing
self.controller.notification.emit("drawing.created", drawing.__json__()) self.controller.notification.emit("drawing.created", drawing.__json__())
self.dump() if dump:
self.dump()
return drawing return drawing
return self._drawings[drawing_id] return self._drawings[drawing_id]
@ -435,15 +439,18 @@ class Project:
@open_required @open_required
@asyncio.coroutine @asyncio.coroutine
def add_link(self, link_id=None): def add_link(self, link_id=None, dump=True):
""" """
Create a link. By default the link is empty Create a link. By default the link is empty
:param dump: Dump topology to disk
""" """
if link_id and link_id in self._links: if link_id and link_id in self._links:
return self._links[link_id] return self._links[link_id]
link = UDPLink(self, link_id=link_id) link = UDPLink(self, link_id=link_id)
self._links[link.id] = link self._links[link.id] = link
self.dump() if dump:
self.dump()
return link return link
@open_required @open_required
@ -626,15 +633,16 @@ class Project:
compute = self.controller.get_compute(node.pop("compute_id")) compute = self.controller.get_compute(node.pop("compute_id"))
name = node.pop("name") name = node.pop("name")
node_id = node.pop("node_id") node_id = node.pop("node_id")
yield from self.add_node(compute, name, node_id, **node) yield from self.add_node(compute, name, node_id, **node, dump=False)
for link_data in topology.get("links", []): for link_data in topology.get("links", []):
link = yield from self.add_link(link_id=link_data["link_id"]) link = yield from self.add_link(link_id=link_data["link_id"])
for node_link in link_data["nodes"]: for node_link in link_data["nodes"]:
node = self.get_node(node_link["node_id"]) node = self.get_node(node_link["node_id"])
yield from link.add_node(node, node_link["adapter_number"], node_link["port_number"], label=node_link.get("label")) yield from link.add_node(node, node_link["adapter_number"], node_link["port_number"], label=node_link.get("label"), dump=False)
for drawing_data in topology.get("drawings", []): for drawing_data in topology.get("drawings", []):
drawing = yield from self.add_drawing(**drawing_data) yield from self.add_drawing(**drawing_data, dump=False)
self.dump()
# We catch all error to be able to rollback the .gns3 to the previous state # We catch all error to be able to rollback the .gns3 to the previous state
except Exception as e: except Exception as e:
for compute in self._project_created_on_compute: for compute in self._project_created_on_compute: