Parcourir la source

Change extension manager to only request from npm when warning has been disclaimed.

Before this commit, the extension manager was always requesting a search from npm, even if the warning had not been disclaimed. This meant that a default JLab install (with extension manager enabled) would always make an external network request.

This changes things so that the network request is only made if the warning has been disclaimed. It actually does more than that, and also cuts out the request to the server, but since the installed packages are also not shown when the disclaimer has not been agreed to, it is okay to prevent that request as well.
Jason Grout il y a 4 ans
Parent
commit
2cb58851dc
1 fichiers modifiés avec 20 ajouts et 24 suppressions
  1. 20 24
      packages/extensionmanager/src/model.ts

+ 20 - 24
packages/extensionmanager/src/model.ts

@@ -745,32 +745,28 @@ export class ListModel extends VDomModel {
    * Emits the `stateChanged` signal on successful completion.
    */
   protected async update(refreshInstalled = false) {
-    // Start both queries before awaiting:
-
-    const searchMapPromise = this.performSearch();
-    const installedMapPromise = this.queryInstalled(refreshInstalled);
-
-    // Await results:
-    const searchMap = await searchMapPromise;
-    const installedMap = await installedMapPromise;
-
-    // Map results to attributes:
-    const installed: IEntry[] = [];
-    for (const key of Object.keys(installedMap)) {
-      installed.push(installedMap[key]);
-    }
-    this._installed = installed.sort(Private.comparator);
-
-    const searchResult: IEntry[] = [];
-    for (const key of Object.keys(searchMap)) {
-      // Filter out installed entries from search results:
-      if (installedMap[key] === undefined) {
-        searchResult.push(searchMap[key]);
-      } else {
-        searchResult.push(installedMap[key]);
+    if (ListModel.isDisclaimed()) {
+      // Start both queries before awaiting:
+      const [searchMap, installedMap] = await Promise.all([this.performSearch(), this.queryInstalled(refreshInstalled)])
+
+      // Map results to attributes:
+      const installed: IEntry[] = [];
+      for (const key of Object.keys(installedMap)) {
+        installed.push(installedMap[key]);
+      }
+      this._installed = installed.sort(Private.comparator);
+
+      const searchResult: IEntry[] = [];
+      for (const key of Object.keys(searchMap)) {
+        // Filter out installed entries from search results:
+        if (installedMap[key] === undefined) {
+          searchResult.push(searchMap[key]);
+        } else {
+          searchResult.push(installedMap[key]);
+        }
       }
+      this._searchResult = searchResult.sort(Private.comparator);
     }
-    this._searchResult = searchResult.sort(Private.comparator);
 
     // Signal updated state
     this.stateChanged.emit(undefined);