Speed up 'create new message' > 2 times

This commit is contained in:
Ruben van de Ven 2019-04-06 12:07:45 +02:00
parent 63f6f15d0f
commit 9a13c0730b
2 changed files with 40 additions and 10 deletions

View file

@ -215,7 +215,7 @@ class Panopticon(object):
(r"/voice", getVoiceHandler(self.voiceStorage)), (r"/voice", getVoiceHandler(self.voiceStorage)),
(r"/(.*)", tornado.web.StaticFileHandler, (r"/(.*)", tornado.web.StaticFileHandler,
{"path": web_dir, "default_filename": 'index.html'}), {"path": web_dir, "default_filename": 'index.html'}),
], debug=False) ], debug=True)
self.application.listen(config['web']['port']) self.application.listen(config['web']['port'])
# self.loop.configure(evt_loop) # self.loop.configure(evt_loop)

View file

@ -1172,7 +1172,7 @@ class Graph {
} }
addMsg() { addMsg(skipRebuild) {
let msg = { let msg = {
"@id": this.language_code.substring( 0, 2 ) + "-n" + Date.now().toString( 36 ), "@id": this.language_code.substring( 0, 2 ) + "-n" + Date.now().toString( 36 ),
"@type": "Msg", "@type": "Msg",
@ -1181,10 +1181,14 @@ class Graph {
"afterrunTime": 0.5, "afterrunTime": 0.5,
} }
this.data.push( msg ); this.data.push( msg );
console.log("skip or not to skip?", skipRebuild);
if(typeof skipRebuild == 'undefined' || !skipRebuild) {
this.updateFromData(); this.updateFromData();
this.build(); this.build();
this.selectMsg(msg); this.selectMsg(msg);
}
return msg; return msg;
} }
@ -1241,7 +1245,21 @@ class Graph {
"conditions": [] "conditions": []
} }
this.data.push( dir ); this.data.push( dir );
this.updateFromData();
let skipDistances;
// orphaned target and source has no other destinations. We can copy the position:
if(this.getDirectionsFrom( source ).length < 1 && this.getDirectionsFrom( target ).length < 1 && this.getDirectionsTo( target ).length < 1) {
skipDistances = true;
let distance = this.distances[source['@id']];
console.log('source distance', distance);
let d = [distance[0] + 1, distance[1]];
console.log('target distance', d);
this.distances[target['@id']] = d;
} else {
skipDistances = false;
}
this.updateFromData(skipDistances);
this.build(); this.build();
return dir; return dir;
} }
@ -1257,18 +1275,28 @@ class Graph {
} }
createConnectedMsg(sourceMsg) { createConnectedMsg(sourceMsg) {
let newMsg = this.addMsg(); console.time('createConnected');
console.time("Add");
let newMsg = this.addMsg(true); // skipRebuild = true, as addDirection() already rebuilds the graph
this.getNodeById(newMsg['@id']).y = this.getNodeById(sourceMsg['@id']).y; this.getNodeById(newMsg['@id']).y = this.getNodeById(sourceMsg['@id']).y;
if(this.getNodeById(sourceMsg['@id']).hasOwnProperty('color')){ if(this.getNodeById(sourceMsg['@id']).hasOwnProperty('color')){
this.getNodeById(newMsg['@id']).color = this.getNodeById(sourceMsg['@id']).color this.getNodeById(newMsg['@id']).color = this.getNodeById(sourceMsg['@id']).color
} }
console.timeEnd("Add");
console.time("direction");
this.addDirection(sourceMsg, newMsg); this.addDirection(sourceMsg, newMsg);
this.build(); console.timeEnd("direction");
console.time("build");
// this.build(); // build is already done in addDirection()
console.timeEnd("build");
// reselect so that overview is updated // reselect so that overview is updated
console.time("Select");
this.selectMsg(newMsg); this.selectMsg(newMsg);
console.timeEnd("Select");
console.timeEnd('createConnected');
} }
getNodeById( id ) { getNodeById( id ) {
@ -1390,7 +1418,7 @@ class Graph {
this.build( true ); this.build( true );
} }
updateFromData() { updateFromData(skipDistances) {
this.messages = this.data.filter(( node ) => node['@type'] == 'Msg' ); this.messages = this.data.filter(( node ) => node['@type'] == 'Msg' );
this.directions = this.data.filter(( node ) => node['@type'] == 'Direction' ); this.directions = this.data.filter(( node ) => node['@type'] == 'Direction' );
this.conditions = this.data.filter(( node ) => node['@type'] == 'Condition' ); this.conditions = this.data.filter(( node ) => node['@type'] == 'Condition' );
@ -1401,7 +1429,9 @@ class Graph {
'class': 'flag-icon ' + this.language_code 'class': 'flag-icon ' + this.language_code
})); }));
if(typeof skipDistances == 'undefined' || !skipDistances) {
this.distances = this.calculateDistancesFromStart(); this.distances = this.calculateDistancesFromStart();
}
// save state; // save state;
this.saveState(); this.saveState();