From 6800b1f7234ebce329f5603859c1b995a767bd55 Mon Sep 17 00:00:00 2001 From: Aditya Toshniwal Date: Tue, 6 Aug 2019 14:02:57 +0100 Subject: [PATCH] Add an optimisation to the internal code responsible for searching for treeview nodes. Fixes #4570 Attached is a tiny but very effective patch to improve the speed of finding a node using path (used internally). If you right click or just click on a node, internally the node is traversed using its path. But currently, it compares with the path of all the open nodes to find a match. So if you 1000+ tables and the tables node is open and if you click on a view, the view path is compared with all the 1000+ tables (and with any other open nodes above) before arriving to path. You're at bad luck if you have more open servers above. Code is changed to check if the path of node to be found starts with the current node path. If it doesn't match, why bother the children's of current node. This change will not show much effect for small data, but it does matter for large servers. One more change is to remove unnecessary calls to find node and use the data available with Main Menu -> Object to enable/disable node context menu items. --- docs/en_US/release_notes_4_12.rst | 1 + web/pgadmin/browser/static/js/menu.js | 7 ++++++- web/pgadmin/static/js/tree/tree.js | 9 +++++++++ 3 files changed, 16 insertions(+), 1 deletion(-) diff --git a/docs/en_US/release_notes_4_12.rst b/docs/en_US/release_notes_4_12.rst index b71efd47f..52621269d 100644 --- a/docs/en_US/release_notes_4_12.rst +++ b/docs/en_US/release_notes_4_12.rst @@ -14,6 +14,7 @@ New features | `Issue #4540 `_ - Use the full tab space for CodeMirror instances on dialogues where appropriate. | `Issue #4549 `_ - Allow a banner to be displayed on the login and other related pages showing custom text. | `Issue #4566 `_ - Allow enhanced cookie protection to be disabled for compatibility with dynamically addressed hosting environments. +| `Issue #4570 `_ - Add an optimisation to the internal code responsible for searching for treeview nodes. Housekeeping ************ diff --git a/web/pgadmin/browser/static/js/menu.js b/web/pgadmin/browser/static/js/menu.js index e76c9ed20..3bcba0220 100644 --- a/web/pgadmin/browser/static/js/menu.js +++ b/web/pgadmin/browser/static/js/menu.js @@ -78,7 +78,12 @@ define([ data: this.data, }).addClass('dropdown-item'); - this.is_disabled = this.disabled(node, item); + if(this.context !== undefined) { + this.is_disabled = this.context.disabled; + } else { + this.is_disabled = this.disabled(node, item); + } + if (this.icon) { url.append($('', { 'class': this.icon, diff --git a/web/pgadmin/static/js/tree/tree.js b/web/pgadmin/static/js/tree/tree.js index 2e616be7f..33397e80d 100644 --- a/web/pgadmin/static/js/tree/tree.js +++ b/web/pgadmin/static/js/tree/tree.js @@ -300,6 +300,15 @@ function findInTree(rootNode, path) { } return (function findInNode(currentNode) { + + /* No point in checking the children if + * the path for currentNode itself is not matching + */ + if (currentNode.path !== undefined && path !== undefined + && !path.startsWith(currentNode.path)) { + return null; + } + for (let i = 0, length = currentNode.children.length; i < length; i++) { const calculatedNode = findInNode(currentNode.children[i]); if (calculatedNode !== null) {