From 9a13c0730b21f076472a73e7e46964f8a635af99 Mon Sep 17 00:00:00 2001 From: Ruben van de Ven Date: Sat, 6 Apr 2019 12:07:45 +0200 Subject: [PATCH] Speed up 'create new message' > 2 times --- hugvey/panopticon.py | 2 +- www/js/hugvey_console.js | 48 ++++++++++++++++++++++++++++++++-------- 2 files changed, 40 insertions(+), 10 deletions(-) diff --git a/hugvey/panopticon.py b/hugvey/panopticon.py index 8a48569..4f34ae4 100644 --- a/hugvey/panopticon.py +++ b/hugvey/panopticon.py @@ -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) diff --git a/www/js/hugvey_console.js b/www/js/hugvey_console.js index 04f83de..a940842 100644 --- a/www/js/hugvey_console.js +++ b/www/js/hugvey_console.js @@ -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();