Permalink
Browse files

Ensure connections added to ConnectionDB on load

Change-Id: Ia29c8c4ed94486098c069b33298b1c66f59d6dde
  • Loading branch information...
ewpatton authored and jisqyv committed Dec 6, 2018
1 parent 3372a19 commit 55b5834229e56c018cc9eddb95a5b233ac81a296
Showing with 25 additions and 8 deletions.
  1. +17 −7 appinventor/blocklyeditor/src/connection_db.js
  2. +8 −1 appinventor/blocklyeditor/src/workspace_svg.js
@@ -1,5 +1,5 @@
// -*- mode: java; c-basic-offset: 2; -*-
// Copyright © 2017 Massachusetts Institute of Technology. All rights reserved.
// Copyright © 2017-2018 Massachusetts Institute of Technology. All rights reserved.

/**
* @license
@@ -27,14 +27,22 @@ goog.require('Blockly.ConnectionDB');
* @private
*/
Blockly.ConnectionDB.prototype.addConnection = function(connection) {
if (connection.inDB_) {
return; // already in the database
}

// Check whether we are in the bulk rendering mode to prevent O(n^2)
// insertion sort runtime.
if (connection.getSourceBlock() && connection.getSourceBlock().workspace &&
connection.getSourceBlock().workspace.bulkRendering) {
// We are in the middle of a bulk rendering option, so just add the
// connection and we will sort later using native array quicksort via the
// Blockly.WorkspaceSvg.requestConnectionDBUpdate() method.
this.push(connection);
connection.inDB_ = true;
return;
}
if (connection.inDB_) {
return; // already in the database
}

if (connection.getSourceBlock().isInFlyout) {
// Don't bother maintaining a database of connections in a flyout.
return;
@@ -53,14 +61,16 @@ Blockly.ConnectionDB.prototype.addConnection = function(connection) {
* @private
*/
Blockly.ConnectionDB.prototype.removeConnection_ = function(connection) {
if (!connection.inDB_) {
return; // connection already not in database
}

if (connection.getSourceBlock() && connection.getSourceBlock().workspace &&
connection.getSourceBlock().workspace.bulkRendering) {
connection.inDB_ = false;
return;
}
if (!connection.inDB_) {
return; // connection already not in database
}

connection.inDB_ = false;
var removalIndex = this.findConnection(connection);
if (removalIndex > -1) {
@@ -1,5 +1,5 @@
// -*- mode: javascript; js-indent-level: 2; -*-
// Copyright © 2016-2017 Massachusetts Institute of Technology. All rights reserved.
// Copyright © 2016-2018 Massachusetts Institute of Technology. All rights reserved.

/**
* @license
@@ -249,6 +249,13 @@ Blockly.WorkspaceSvg.prototype.isDrawerShowing = function() {
Blockly.WorkspaceSvg.prototype.render = function(blocks) {
this.rendered = true;
this.bulkRendering = true;
// In bulk rendering mode, the database accepts all new connections to be
// sorted later. If we don't clear this, then we can end up with multiple
// entries in the DB for the same connection. This isn't necessarily bad,
// but it may decrease performance.
this.connectionDBList.forEach(function (db) {
db.length = 0; // clear the databases
});
Blockly.Field.startCache();
try {
if (Blockly.Instrument.isOn) {

0 comments on commit 55b5834

Please sign in to comment.