Skip to content
Snippets Groups Projects
Commit 96c5614c authored by inso's avatar inso
Browse files

Not loading nodes content on startup -> faster starting

parent 77851f1d
No related branches found
No related tags found
No related merge requests found
......@@ -478,7 +478,7 @@ class Community(QObject):
nodes_data = []
for node in self._network.root_nodes:
nodes_data.append(node.jsonify())
nodes_data.append(node.jsonify_root_node())
data = {'currency': self.currency,
'peers': nodes_data}
......
......@@ -26,7 +26,7 @@ class Network(Watcher):
Constructor of a network
:param str currency: The currency name of the community
:param list nodes: The nodes of the network
:param list nodes: The root nodes of the network
'''
super().__init__()
self._root_nodes = nodes
......@@ -63,11 +63,12 @@ class Network(Watcher):
if node.pubkey not in [n.pubkey for n in self.nodes]:
self.add_node(node)
logging.debug("Loading : {:}".format(data['pubkey']))
for n in self.nodes:
try:
n.changed.disconnect()
except TypeError:
pass
else:
other_node = [n for n in self.nodes if n.pubkey == node.pubkey][0]
if other_node.block < node.block:
other_node.block = node.block
other_node.last_change = node.last_change
other_node.state = node.state
@classmethod
def from_json(cls, currency, json_data):
......
......@@ -71,7 +71,6 @@ class Node(QObject):
node = cls(peer.currency, peer.endpoints, "", peer.pubkey, 0,
Node.ONLINE, time.time())
node.refresh_state()
logging.debug("Node from address : {:}".format(str(node)))
return node
......@@ -90,7 +89,6 @@ class Node(QObject):
node = cls(peer.currency, peer.endpoints, "", "", 0,
Node.ONLINE, time.time())
node.refresh_state()
logging.debug("Node from peer : {:}".format(str(node)))
return node
......@@ -99,6 +97,7 @@ class Node(QObject):
endpoints = []
uid = ""
pubkey = ""
block = 0
last_change = time.time()
state = Node.ONLINE
logging.debug(data)
......@@ -117,24 +116,38 @@ class Node(QObject):
if 'last_change' in data:
last_change = data['last_change']
if 'block' in data:
block = data['block']
if 'state' in data:
state = data['state']
else:
logging.debug("Error : no state in node")
node = cls(currency, endpoints, uid, pubkey, 0,
node = cls(currency, endpoints, uid, pubkey, block,
state, last_change)
node.refresh_state()
logging.debug("Node from json : {:}".format(str(node)))
return node
def jsonify_root_node(self):
logging.debug("Saving root node : {:}".format(str(self)))
data = {'pubkey': self._pubkey,
'uid': self._uid,
'currency': self._currency}
endpoints = []
for e in self._endpoints:
endpoints.append(e.inline())
data['endpoints'] = endpoints
return data
def jsonify(self):
logging.debug("Saving node : {:}".format(str(self)))
data = {'pubkey': self._pubkey,
'uid': self._uid,
'currency': self._currency,
'state': self._state,
'last_change': self._last_change}
'last_change': self._last_change,
'block': self.block}
endpoints = []
for e in self._endpoints:
endpoints.append(e.inline())
......
......@@ -32,6 +32,8 @@ class ConfigureContactDialog(QDialog, Ui_ConfigureContactDialog):
'pubkey': contact.pubkey}
elif type(contact) is dict:
self.contact = contact
else:
self.contact = None
if index_edit is not None:
self.contact = account.contacts[index_edit]
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment