perf: adjust the order of command cases in switch by calling frequence
This commit is contained in:
		
							
								
								
									
										39
									
								
								src/home.ts
									
									
									
									
									
								
							
							
						
						
									
										39
									
								
								src/home.ts
									
									
									
									
									
								
							@@ -35,6 +35,25 @@ export default class DSHome {
 | 
			
		||||
      async (message) => {
 | 
			
		||||
        const data = message.data
 | 
			
		||||
        switch (message.command) {
 | 
			
		||||
          // ----------------- frequent -----------------------
 | 
			
		||||
          case 'getUserToken':
 | 
			
		||||
            const userToken = this.user.getUserTokenFromLocal()
 | 
			
		||||
            if (userToken === undefined) {
 | 
			
		||||
              panel.webview.postMessage({ command: 'getUserToken', data: {userToken: ''}})
 | 
			
		||||
              break;
 | 
			
		||||
            } else {
 | 
			
		||||
              panel.webview.postMessage({ command: 'getUserToken', data: {userToken: userToken}})
 | 
			
		||||
              break;
 | 
			
		||||
            }
 | 
			
		||||
          case 'getUsername':
 | 
			
		||||
            const username = this.user.getUsernameFromLocal()
 | 
			
		||||
            if (username === undefined) {
 | 
			
		||||
              panel.webview.postMessage({command: 'getUsername', data: {username: ''}})
 | 
			
		||||
              break;
 | 
			
		||||
            } else {
 | 
			
		||||
              panel.webview.postMessage({command: 'getUsername', data: {username: username}})
 | 
			
		||||
              break;
 | 
			
		||||
            }
 | 
			
		||||
          case 'firstOpenRemoteFolder':
 | 
			
		||||
            const path = data.path
 | 
			
		||||
            await this.remoteContainer.firstConnect(data.host, data.username, data.port)
 | 
			
		||||
@@ -50,15 +69,7 @@ export default class DSHome {
 | 
			
		||||
          case 'openRemoteFolder':
 | 
			
		||||
            this.remoteContainer.openRemoteFolder(data.host, data.path);
 | 
			
		||||
            break;
 | 
			
		||||
          case 'getUserToken':
 | 
			
		||||
            const userToken = this.user.getUserTokenFromLocal()
 | 
			
		||||
            if (userToken === undefined) {
 | 
			
		||||
              panel.webview.postMessage({ command: 'getUserToken', data: {userToken: ''}})
 | 
			
		||||
              break;
 | 
			
		||||
            } else {
 | 
			
		||||
              panel.webview.postMessage({ command: 'getUserToken', data: {userToken: userToken}})
 | 
			
		||||
              break;
 | 
			
		||||
            }
 | 
			
		||||
          // ----------------- not frequent -----------------------
 | 
			
		||||
          case 'setUserToken':
 | 
			
		||||
            this.user.setUserTokenToLocal(data.userToken)
 | 
			
		||||
            if (data.userToken === this.user.getUserTokenFromLocal()) {
 | 
			
		||||
@@ -68,15 +79,6 @@ export default class DSHome {
 | 
			
		||||
              panel.webview.postMessage({ command: 'setUserToken', data: {ok: false}})
 | 
			
		||||
              break;
 | 
			
		||||
            }
 | 
			
		||||
          case 'getUsername':
 | 
			
		||||
            const username = this.user.getUsernameFromLocal()
 | 
			
		||||
            if (username === undefined) {
 | 
			
		||||
              panel.webview.postMessage({command: 'getUsername', data: {username: ''}})
 | 
			
		||||
              break;
 | 
			
		||||
            } else {
 | 
			
		||||
              panel.webview.postMessage({command: 'getUsername', data: {username: username}})
 | 
			
		||||
              break;
 | 
			
		||||
            }
 | 
			
		||||
          case 'setUsername':
 | 
			
		||||
            this.user.setUsernameToLocal(data.username);
 | 
			
		||||
            if (data.username === this.user.getUsernameFromLocal()) {
 | 
			
		||||
@@ -117,7 +119,6 @@ export default class DSHome {
 | 
			
		||||
              utils.createSSHKey();
 | 
			
		||||
              defaultPublicKey = utils.getDefaultPublicKey();
 | 
			
		||||
            }
 | 
			
		||||
 | 
			
		||||
            panel.webview.postMessage({ command: 'getDefaultPublicKey', data: {defaultPublicKey: defaultPublicKey}})
 | 
			
		||||
        }
 | 
			
		||||
      },
 | 
			
		||||
 
 | 
			
		||||
		Reference in New Issue
	
	Block a user