Skip to content

Commit 82ba18f

Browse files
rosen-vladimirovDimitar Kerezov
authored and
Dimitar Kerezov
committed
Cache sockets per app per device
1 parent e2205c6 commit 82ba18f

File tree

3 files changed

+17
-6
lines changed

3 files changed

+17
-6
lines changed

lib/services/livesync/android-livesync-service.ts

+1-1
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@ export class AndroidLiveSyncService extends PlatformLiveSyncServiceBase implemen
1313
super($fs, $logger, $platformsData, $projectFilesManager, $devicePathProvider, $projectFilesProvider);
1414
}
1515

16-
public getDeviceLiveSyncService(device: Mobile.IDevice): INativeScriptDeviceLiveSyncService {
16+
protected _getDeviceLiveSyncService(device: Mobile.IDevice): INativeScriptDeviceLiveSyncService {
1717
const service = this.$injector.resolve<INativeScriptDeviceLiveSyncService>(AndroidDeviceLiveSyncService, { _device: device });
1818
return service;
1919
}

lib/services/livesync/ios-livesync-service.ts

+1-1
Original file line numberDiff line numberDiff line change
@@ -67,7 +67,7 @@ export class IOSLiveSyncService extends PlatformLiveSyncServiceBase implements I
6767
}
6868
}
6969

70-
public getDeviceLiveSyncService(device: Mobile.IDevice): INativeScriptDeviceLiveSyncService {
70+
protected _getDeviceLiveSyncService(device: Mobile.IDevice): INativeScriptDeviceLiveSyncService {
7171
const service = this.$injector.resolve<INativeScriptDeviceLiveSyncService>(IOSDeviceLiveSyncService, { _device: device });
7272
return service;
7373
}

lib/services/livesync/platform-livesync-service-base.ts

+15-4
Original file line numberDiff line numberDiff line change
@@ -3,18 +3,29 @@ import * as util from "util";
33
import { APP_FOLDER_NAME } from "../../constants";
44

55
export abstract class PlatformLiveSyncServiceBase {
6+
private _deviceLiveSyncServicesCache: IDictionary<INativeScriptDeviceLiveSyncService> = {};
7+
68
constructor(protected $fs: IFileSystem,
79
protected $logger: ILogger,
810
protected $platformsData: IPlatformsData,
911
protected $projectFilesManager: IProjectFilesManager,
1012
private $devicePathProvider: IDevicePathProvider,
1113
private $projectFilesProvider: IProjectFilesProvider) { }
1214

13-
public abstract getDeviceLiveSyncService(device: Mobile.IDevice): INativeScriptDeviceLiveSyncService;
15+
public getDeviceLiveSyncService(device: Mobile.IDevice, applicationIdentifier: string): INativeScriptDeviceLiveSyncService {
16+
const key = device.deviceInfo.identifier + applicationIdentifier;
17+
if (!this._deviceLiveSyncServicesCache[key]) {
18+
this._deviceLiveSyncServicesCache[key] = this._getDeviceLiveSyncService(device);
19+
}
20+
21+
return this._deviceLiveSyncServicesCache[key];
22+
}
23+
24+
protected abstract _getDeviceLiveSyncService(device: Mobile.IDevice): INativeScriptDeviceLiveSyncService;
1425

1526
public async refreshApplication(projectData: IProjectData, liveSyncInfo: ILiveSyncResultInfo): Promise<void> {
1627
if (liveSyncInfo.isFullSync || liveSyncInfo.modifiedFilesData.length) {
17-
const deviceLiveSyncService = this.getDeviceLiveSyncService(liveSyncInfo.deviceAppData.device);
28+
const deviceLiveSyncService = this.getDeviceLiveSyncService(liveSyncInfo.deviceAppData.device, projectData.projectId);
1829
this.$logger.info("Refreshing application...");
1930
await deviceLiveSyncService.refreshApplication(projectData, liveSyncInfo);
2031
}
@@ -23,7 +34,7 @@ export abstract class PlatformLiveSyncServiceBase {
2334
public async fullSync(syncInfo: IFullSyncInfo): Promise<ILiveSyncResultInfo> {
2435
const projectData = syncInfo.projectData;
2536
const device = syncInfo.device;
26-
const deviceLiveSyncService = this.getDeviceLiveSyncService(device);
37+
const deviceLiveSyncService = this.getDeviceLiveSyncService(device, syncInfo.projectData.projectId);
2738
const platformData = this.$platformsData.getPlatformData(device.deviceInfo.platform, projectData);
2839
const deviceAppData = await this.getAppData(syncInfo);
2940

@@ -79,7 +90,7 @@ export abstract class PlatformLiveSyncServiceBase {
7990
const localToDevicePaths = await this.$projectFilesManager.createLocalToDevicePaths(deviceAppData, projectFilesPath, mappedFiles, []);
8091
modifiedLocalToDevicePaths.push(...localToDevicePaths);
8192

82-
const deviceLiveSyncService = this.getDeviceLiveSyncService(device);
93+
const deviceLiveSyncService = this.getDeviceLiveSyncService(device, projectData.projectId);
8394
deviceLiveSyncService.removeFiles(deviceAppData, localToDevicePaths);
8495
}
8596

0 commit comments

Comments
 (0)