From 67931912fa571bba7863038b072e9fc04c63ade5 Mon Sep 17 00:00:00 2001 From: rosen-vladimirov Date: Mon, 2 Jul 2018 19:12:46 +0300 Subject: [PATCH] feat: Speed up device detection Speed up device detection by: * removing duplicate calls to all device detection services * cache the Promise of initialize method - this way even when multiple calls are executed simultaneously, the result of the first one will be used. This allows Sidekick to call the method asynchronously. * do not execute iOS device detection login in case `--emulator` is passed Remove several public methods from the service - make them protected as we already have tests for them. Remove all calls to detectCurrentlyAttachedDevices method outside of the service - the initialize method will do it anyway, so no need to call it externally. Remove duplicate calls in the startLookingForDevices method - previously it had to filter which device detection services to call. As now each device detection service checks its platform, we can safely call all of them and rely on their filters to skip the execution. --- lib/commands/debug.ts | 4 ---- lib/common | 2 +- lib/declarations.d.ts | 7 ++----- lib/helpers/livesync-command-helper.ts | 6 +++--- lib/services/test-execution-service.ts | 1 - test/debug.ts | 1 - 6 files changed, 6 insertions(+), 15 deletions(-) diff --git a/lib/commands/debug.ts b/lib/commands/debug.ts index 5ed5ec1d7e..d11de92990 100644 --- a/lib/commands/debug.ts +++ b/lib/commands/debug.ts @@ -35,8 +35,6 @@ export class DebugPlatformCommand implements ICommand { return; } - await this.$devicesService.detectCurrentlyAttachedDevices({ shouldReturnImmediateResult: false, platform: this.platform }); - await this.$liveSyncCommandHelper.executeLiveSyncOperation([selectedDeviceForDebug], this.platform, { deviceDebugMap: { [selectedDeviceForDebug.deviceInfo.identifier]: true @@ -52,8 +50,6 @@ export class DebugPlatformCommand implements ICommand { this.$errors.fail(DebugCommandErrors.UNABLE_TO_USE_FOR_DEVICE_AND_EMULATOR); } - await this.$devicesService.detectCurrentlyAttachedDevices({ platform: this.platform, shouldReturnImmediateResult: false }); - if (this.$options.device) { const device = await this.$devicesService.getDevice(this.$options.device); return device; diff --git a/lib/common b/lib/common index 218dbb7bb1..b8ec069f9c 160000 --- a/lib/common +++ b/lib/common @@ -1 +1 @@ -Subproject commit 218dbb7bb1b7dc2429431c8c01aac400974a0de8 +Subproject commit b8ec069f9ce1722129a8e2f05892e58e6b04bab4 diff --git a/lib/declarations.d.ts b/lib/declarations.d.ts index ca9107238a..f131ec9c0c 100644 --- a/lib/declarations.d.ts +++ b/lib/declarations.d.ts @@ -405,9 +405,6 @@ interface IPlatformTemplate { platformTemplate: string; } -interface IEmulator { - emulator: boolean; -} interface IClean { clean: boolean; @@ -449,7 +446,7 @@ interface IPort { port: Number; } -interface IOptions extends ICommonOptions, IBundleString, IPlatformTemplate, IEmulator, IClean, IProvision, ITeamIdentifier, IAndroidReleaseOptions, INpmInstallConfigurationOptions, IPort, IEnvOptions { +interface IOptions extends ICommonOptions, IBundleString, IPlatformTemplate, IHasEmulatorOption, IClean, IProvision, ITeamIdentifier, IAndroidReleaseOptions, INpmInstallConfigurationOptions, IPort, IEnvOptions { all: boolean; client: boolean; compileSdk: number; @@ -482,7 +479,7 @@ interface IAppFilesUpdaterOptions extends IBundle, IRelease, IOptionalWatchAllFi interface IPlatformBuildData extends IAppFilesUpdaterOptions, IBuildConfig, IEnvOptions { } -interface IDeviceEmulator extends IEmulator, IDeviceIdentifier { } +interface IDeviceEmulator extends IHasEmulatorOption, IDeviceIdentifier { } interface IRunPlatformOptions extends IJustLaunch, IDeviceEmulator { } diff --git a/lib/helpers/livesync-command-helper.ts b/lib/helpers/livesync-command-helper.ts index 52adbecc8f..45a674f13d 100644 --- a/lib/helpers/livesync-command-helper.ts +++ b/lib/helpers/livesync-command-helper.ts @@ -21,15 +21,15 @@ export class LiveSyncCommandHelper implements ILiveSyncCommandHelper { } public async executeCommandLiveSync(platform?: string, additionalOptions?: ILiveSyncCommandHelperAdditionalOptions) { + const emulator = this.$options.emulator; await this.$devicesService.initialize({ deviceId: this.$options.device, - platform: platform, - emulator: this.$options.emulator, + platform, + emulator, skipDeviceDetectionInterval: true, skipInferPlatform: !platform }); - await this.$devicesService.detectCurrentlyAttachedDevices({ shouldReturnImmediateResult: false, platform: platform }); const devices = this.$devicesService.getDeviceInstances() .filter(d => !platform || d.deviceInfo.platform.toLowerCase() === platform.toLowerCase()); diff --git a/lib/services/test-execution-service.ts b/lib/services/test-execution-service.ts index b0c3de388a..8105310c29 100644 --- a/lib/services/test-execution-service.ts +++ b/lib/services/test-execution-service.ts @@ -44,7 +44,6 @@ class TestExecutionService implements ITestExecutionService { deviceId: this.$options.device, emulator: this.$options.emulator }); - await this.$devicesService.detectCurrentlyAttachedDevices(); const projectFilesPath = path.join(platformData.appDestinationDirectoryPath, constants.APP_FOLDER_NAME); const configOptions: IKarmaConfigOptions = JSON.parse(launcherConfig); diff --git a/test/debug.ts b/test/debug.ts index 9ce6c7a2e6..8e55b0c22a 100644 --- a/test/debug.ts +++ b/test/debug.ts @@ -36,7 +36,6 @@ function createTestInjector(): IInjector { }); testInjector.register('devicesService', { initialize: async () => { /* Intentionally left blank */ }, - detectCurrentlyAttachedDevices: async () => { /* Intentionally left blank */ }, getDeviceInstances: (): any[] => { return []; }, execute: async (): Promise => ({}) });