From 2c024a4488263e585f601c89461c524560192ba9 Mon Sep 17 00:00:00 2001 From: Pritesh Nandgaonkar Date: Wed, 22 May 2019 03:44:11 -0700 Subject: [PATCH] Call exportPersistedState only for clients of a selected device Summary: Call `exportPersistedState` only for the clients of selectedDevice. This will fasten up our export, we do not need to call `exportPersistedState` for the clients of nonSelectedDevice. {F159322777} Reviewed By: passy Differential Revision: D15440652 fbshipit-source-id: e018603cfeb56fec462b54a6897fb254cc361390 --- src/utils/exportData.js | 30 ++++++++++++++++++++---------- 1 file changed, 20 insertions(+), 10 deletions(-) diff --git a/src/utils/exportData.js b/src/utils/exportData.js index 4c3378789..92a31be40 100644 --- a/src/utils/exportData.js +++ b/src/utils/exportData.js @@ -191,6 +191,10 @@ export async function getStoreExport( const {clients} = state.connections; const {pluginStates} = state; const {plugins} = state; + const {selectedDevice} = store.getState().connections; + if (!selectedDevice) { + throw new Error('Please select a device before exporting data.'); + } const newPluginState = {...pluginStates}; // TODO: T39612653 Make Client mockable. Currently rsocket logic is tightly coupled. // Not passing the entire state as currently Client is not mockable. @@ -207,6 +211,9 @@ export async function getStoreExport( }); const errorArray: Array = []; for (let client of clients) { + if (!client.id.includes(selectedDevice.serial)) { + continue; + } for (let plugin of client.plugins) { const pluginClass: ?Class< FlipperDevicePlugin<> | FlipperPlugin<>, @@ -230,7 +237,6 @@ export async function getStoreExport( } const {activeNotifications} = store.getState().notifications; - const {selectedDevice} = store.getState().connections; const {devicePlugins} = store.getState().plugins; const exportData = await processStore( @@ -249,16 +255,20 @@ export function exportStore( ): Promise<{serializedString: string, errorArray: Array}> { getLogger().track('usage', EXPORT_FLIPPER_TRACE_EVENT); return new Promise(async (resolve, reject) => { - const {exportData, errorArray} = await getStoreExport(store); - if (!exportData) { - console.error('Make sure a device is connected'); - reject('No device is selected'); + try { + const {exportData, errorArray} = await getStoreExport(store); + if (!exportData) { + console.error('Make sure a device is connected'); + reject('No device is selected'); + } + const serializedString = serialize(exportData); + if (serializedString.length <= 0) { + reject('Serialize function returned empty string'); + } + resolve({serializedString, errorArray}); + } catch (e) { + reject(e); } - const serializedString = serialize(exportData); - if (serializedString.length <= 0) { - reject('Serialize function returned empty string'); - } - resolve({serializedString, errorArray}); }); }