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"/(.*)", tornado.web.StaticFileHandler,
{"path": web_dir, "default_filename": 'index.html'}),
], debug=False)
], debug=True)
self.application.listen(config['web']['port'])
# self.loop.configure(evt_loop)

View file

@ -1172,7 +1172,7 @@ class Graph {
}
addMsg() {
addMsg(skipRebuild) {
let msg = {
"@id": this.language_code.substring( 0, 2 ) + "-n" + Date.now().toString( 36 ),
"@type": "Msg",
@ -1181,10 +1181,14 @@ class Graph {
"afterrunTime": 0.5,
}
this.data.push( msg );
this.updateFromData();
this.build();
this.selectMsg(msg);
console.log("skip or not to skip?", skipRebuild);
if(typeof skipRebuild == 'undefined' || !skipRebuild) {
this.updateFromData();
this.build();
this.selectMsg(msg);
}
return msg;
}
@ -1241,7 +1245,21 @@ class Graph {
"conditions": []
}
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();
return dir;
}
@ -1257,18 +1275,28 @@ class Graph {
}
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;
if(this.getNodeById(sourceMsg['@id']).hasOwnProperty('color')){
this.getNodeById(newMsg['@id']).color = this.getNodeById(sourceMsg['@id']).color
}
console.timeEnd("Add");
console.time("direction");
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
console.time("Select");
this.selectMsg(newMsg);
console.timeEnd("Select");
console.timeEnd('createConnected');
}
getNodeById( id ) {
@ -1390,7 +1418,7 @@ class Graph {
this.build( true );
}
updateFromData() {
updateFromData(skipDistances) {
this.messages = this.data.filter(( node ) => node['@type'] == 'Msg' );
this.directions = this.data.filter(( node ) => node['@type'] == 'Direction' );
this.conditions = this.data.filter(( node ) => node['@type'] == 'Condition' );
@ -1401,7 +1429,9 @@ class Graph {
'class': 'flag-icon ' + this.language_code
}));
this.distances = this.calculateDistancesFromStart();
if(typeof skipDistances == 'undefined' || !skipDistances) {
this.distances = this.calculateDistancesFromStart();
}
// save state;
this.saveState();