فهرست منبع

HUE-6794 [assist] Only update the tables in the assistant when there's been a change

Johan Ahlen 8 سال پیش
والد
کامیت
615237a
1فایلهای تغییر یافته به همراه31 افزوده شده و 15 حذف شده
  1. 31 15
      desktop/core/src/desktop/templates/assist.mako

+ 31 - 15
desktop/core/src/desktop/templates/assist.mako

@@ -1931,6 +1931,8 @@ from notebook.conf import get_ordered_interpreters
           }).join('.');
         };
 
+        var activeTableIndex = {};
+
         var handleLocationUpdate = function (activeLocations) {
           if (!activeLocations) {
             return;
@@ -1939,26 +1941,40 @@ from notebook.conf import get_ordered_interpreters
           self.activeStatementIndex(activeLocations.activeStatementIndex);
 
           if (activeLocations.activeStatementLocations) {
-            var tableIndex = {};
+            var updateTables = false;
+            var tableQidIndex = {};
             activeLocations.activeStatementLocations.forEach(function (location) {
               if (location.type === 'table') {
-                tableIndex[createQualifiedIdentifier(location.identifierChain)] = {
-                  name: location.identifierChain[location.identifierChain.length - 1].name,
-                  identifierChain: location.identifierChain
-                };
+                var qid = createQualifiedIdentifier(location.identifierChain);
+                tableQidIndex[qid] = true;
+                if (!activeTableIndex[qid]) {
+                  activeTableIndex[createQualifiedIdentifier(location.identifierChain)] = {
+                    name: location.identifierChain[location.identifierChain.length - 1].name,
+                    identifierChain: location.identifierChain
+                  };
+                  updateTables = true;
+                }
+              }
+            });
+            Object.keys(activeTableIndex).forEach(function (key) {
+              if (!tableQidIndex[key]) {
+                delete activeTableIndex[key];
+                updateTables = true;
               }
             });
 
-            self.activeTables($.map(tableIndex, function (value) {
-              return new MetastoreTable({
-                database: {
-                  name: value.identifierChain.length === 2 ? value.identifierChain[0].name : activeLocations.defaultDatabase
-                },
-                type: 'table',
-                sourceType: activeLocations.type,
-                name: value.name
-              });
-            }));
+            if (updateTables) {
+              self.activeTables($.map(activeTableIndex, function (value) {
+                return new MetastoreTable({
+                  database: {
+                    name: value.identifierChain.length === 2 ? value.identifierChain[0].name : activeLocations.defaultDatabase
+                  },
+                  type: 'table',
+                  sourceType: activeLocations.type,
+                  name: value.name
+                });
+              }));
+            }
           }
         };