Stop storing device logs on the device object and in the plugin
Summary: Logs were stored hardcoded on the Device object first, this diff makes it normal plugin state. This makes sure that we can use the same abstractions as in all plugins that store large data sets, and that we can leverage the upcoming DataSource abstraction. Reviewed By: nikoant Differential Revision: D26127243 fbshipit-source-id: 7c386a615fa7989f35ba0df5b7c1d218d37b57a2
This commit is contained in:
committed by
Facebook GitHub Bot
parent
f2ade40239
commit
7cc55daf34
@@ -19,7 +19,6 @@ Object {
|
||||
"devices": Array [
|
||||
Object {
|
||||
"deviceType": "physical",
|
||||
"logs": Array [],
|
||||
"os": "Android",
|
||||
"serial": "serial",
|
||||
"title": "MockAndroidDevice",
|
||||
@@ -28,7 +27,6 @@ Object {
|
||||
"selectedApp": "TestApp#Android#MockAndroidDevice#serial",
|
||||
"selectedDevice": Object {
|
||||
"deviceType": "physical",
|
||||
"logs": Array [],
|
||||
"os": "Android",
|
||||
"serial": "serial",
|
||||
"title": "MockAndroidDevice",
|
||||
|
||||
@@ -86,7 +86,6 @@ export default class AndroidDevice extends BaseDevice {
|
||||
}
|
||||
|
||||
clearLogs(): Promise<void> {
|
||||
this.logEntries = [];
|
||||
return this.executeShell(['logcat', '-c']);
|
||||
}
|
||||
|
||||
@@ -96,7 +95,6 @@ export default class AndroidDevice extends BaseDevice {
|
||||
deviceType: this.deviceType,
|
||||
title: this.title,
|
||||
os: this.os,
|
||||
logEntries: [...this.logEntries],
|
||||
screenshotHandle: null,
|
||||
});
|
||||
}
|
||||
|
||||
@@ -8,7 +8,7 @@
|
||||
*/
|
||||
|
||||
import BaseDevice from './BaseDevice';
|
||||
import type {DeviceLogEntry, DeviceType} from 'flipper-plugin';
|
||||
import type {DeviceType} from 'flipper-plugin';
|
||||
import {OS, DeviceShell} from './BaseDevice';
|
||||
import {SupportFormRequestDetailsState} from '../reducers/supportForm';
|
||||
|
||||
@@ -18,19 +18,16 @@ export default class ArchivedDevice extends BaseDevice {
|
||||
deviceType: DeviceType;
|
||||
title: string;
|
||||
os: OS;
|
||||
logEntries: Array<DeviceLogEntry>;
|
||||
screenshotHandle: string | null;
|
||||
source?: string;
|
||||
supportRequestDetails?: SupportFormRequestDetailsState;
|
||||
}) {
|
||||
super(options.serial, options.deviceType, options.title, options.os);
|
||||
this.logs = options.logEntries;
|
||||
this.source = options.source || '';
|
||||
this.supportRequestDetails = options.supportRequestDetails;
|
||||
this.archivedScreenshotHandle = options.screenshotHandle;
|
||||
}
|
||||
|
||||
logs: Array<DeviceLogEntry>;
|
||||
archivedScreenshotHandle: string | null;
|
||||
isArchived = true;
|
||||
|
||||
@@ -40,15 +37,6 @@ export default class ArchivedDevice extends BaseDevice {
|
||||
|
||||
supportRequestDetails?: SupportFormRequestDetailsState;
|
||||
|
||||
getLogs() {
|
||||
return this.logs;
|
||||
}
|
||||
|
||||
clearLogs(): Promise<void> {
|
||||
this.logs = [];
|
||||
return Promise.resolve();
|
||||
}
|
||||
|
||||
spawnShell(): DeviceShell | undefined | null {
|
||||
return null;
|
||||
}
|
||||
|
||||
@@ -33,7 +33,6 @@ export type DeviceExport = {
|
||||
title: string;
|
||||
deviceType: DeviceType;
|
||||
serial: string;
|
||||
logs: Array<DeviceLogEntry>;
|
||||
pluginStates: Record<string, any>;
|
||||
};
|
||||
|
||||
@@ -71,7 +70,6 @@ export default class BaseDevice {
|
||||
icon: string | null | undefined;
|
||||
|
||||
logListeners: Map<Symbol, DeviceLogListener> = new Map();
|
||||
logEntries: Array<DeviceLogEntry> = [];
|
||||
isArchived: boolean = false;
|
||||
// if imported, stores the original source location
|
||||
source = '';
|
||||
@@ -116,7 +114,6 @@ export default class BaseDevice {
|
||||
title: this.title,
|
||||
deviceType: this.deviceType,
|
||||
serial: this.serial,
|
||||
logs: this.getLogs(),
|
||||
};
|
||||
}
|
||||
|
||||
@@ -146,25 +143,9 @@ export default class BaseDevice {
|
||||
}
|
||||
|
||||
addLogEntry(entry: DeviceLogEntry) {
|
||||
this.logEntries.push(entry);
|
||||
this._notifyLogListeners(entry);
|
||||
}
|
||||
|
||||
// TODO: remove getLogs T70688226
|
||||
getLogs(startDate: Date | null = null) {
|
||||
return startDate != null
|
||||
? this.logEntries.filter((log) => {
|
||||
return log.date > startDate;
|
||||
})
|
||||
: this.logEntries;
|
||||
}
|
||||
|
||||
clearLogs(): Promise<void> {
|
||||
// Only for device types that allow clearing.
|
||||
this.logEntries = [];
|
||||
return Promise.resolve();
|
||||
}
|
||||
|
||||
removeLogListener(id: Symbol) {
|
||||
this.logListeners.delete(id);
|
||||
}
|
||||
|
||||
@@ -205,7 +205,6 @@ export default class MetroDevice extends BaseDevice {
|
||||
deviceType: this.deviceType,
|
||||
title: this.title,
|
||||
os: this.os,
|
||||
logEntries: [...this.logEntries],
|
||||
screenshotHandle: null,
|
||||
});
|
||||
}
|
||||
|
||||
@@ -108,7 +108,6 @@ test('test generateClientIndentifierWithSalt helper function', () => {
|
||||
deviceType: 'emulator',
|
||||
title: 'TestiPhone',
|
||||
os: 'iOS',
|
||||
logEntries: [],
|
||||
screenshotHandle: null,
|
||||
});
|
||||
const identifier = generateClientIdentifier(device, 'app');
|
||||
@@ -123,7 +122,6 @@ test('test generateClientFromClientWithSalt helper function', () => {
|
||||
deviceType: 'emulator',
|
||||
title: 'TestiPhone',
|
||||
os: 'iOS',
|
||||
logEntries: [],
|
||||
screenshotHandle: null,
|
||||
});
|
||||
const client = generateClientFromDevice(device, 'app');
|
||||
@@ -154,7 +152,6 @@ test('test generateClientFromDevice helper function', () => {
|
||||
deviceType: 'emulator',
|
||||
title: 'TestiPhone',
|
||||
os: 'iOS',
|
||||
logEntries: [],
|
||||
screenshotHandle: null,
|
||||
});
|
||||
const client = generateClientFromDevice(device, 'app');
|
||||
@@ -175,7 +172,6 @@ test('test generateClientIdentifier helper function', () => {
|
||||
deviceType: 'emulator',
|
||||
title: 'TestiPhone',
|
||||
os: 'iOS',
|
||||
logEntries: [],
|
||||
screenshotHandle: null,
|
||||
});
|
||||
const identifier = generateClientIdentifier(device, 'app');
|
||||
@@ -218,7 +214,6 @@ test('test processStore function for an iOS device connected', async () => {
|
||||
deviceType: 'emulator',
|
||||
title: 'TestiPhone',
|
||||
os: 'iOS',
|
||||
logEntries: [],
|
||||
screenshotHandle: null,
|
||||
}),
|
||||
pluginStates: {},
|
||||
@@ -254,7 +249,6 @@ test('test processStore function for an iOS device connected with client plugin
|
||||
deviceType: 'emulator',
|
||||
title: 'TestiPhone',
|
||||
os: 'iOS',
|
||||
logEntries: [],
|
||||
screenshotHandle: null,
|
||||
});
|
||||
const client = generateClientFromDevice(device, 'testapp');
|
||||
@@ -305,7 +299,6 @@ test('test processStore function to have only the client for the selected device
|
||||
deviceType: 'emulator',
|
||||
title: 'TestiPhone',
|
||||
os: 'iOS',
|
||||
logEntries: [],
|
||||
screenshotHandle: null,
|
||||
});
|
||||
const unselectedDevice = new ArchivedDevice({
|
||||
@@ -313,7 +306,6 @@ test('test processStore function to have only the client for the selected device
|
||||
deviceType: 'emulator',
|
||||
title: 'TestiPhone',
|
||||
os: 'iOS',
|
||||
logEntries: [],
|
||||
screenshotHandle: null,
|
||||
});
|
||||
|
||||
@@ -374,7 +366,6 @@ test('test processStore function to have multiple clients for the selected devic
|
||||
deviceType: 'emulator',
|
||||
title: 'TestiPhone',
|
||||
os: 'iOS',
|
||||
logEntries: [],
|
||||
screenshotHandle: null,
|
||||
});
|
||||
|
||||
@@ -441,7 +432,6 @@ test('test processStore function for device plugin state and no clients', async
|
||||
deviceType: 'emulator',
|
||||
title: 'TestiPhone',
|
||||
os: 'iOS',
|
||||
logEntries: [],
|
||||
screenshotHandle: null,
|
||||
});
|
||||
const json = await processStore({
|
||||
@@ -479,7 +469,6 @@ test('test processStore function for unselected device plugin state and no clien
|
||||
deviceType: 'emulator',
|
||||
title: 'TestiPhone',
|
||||
os: 'iOS',
|
||||
logEntries: [],
|
||||
screenshotHandle: null,
|
||||
});
|
||||
const json = await processStore({
|
||||
@@ -513,7 +502,6 @@ test('test processStore function for notifications for selected device', async (
|
||||
deviceType: 'emulator',
|
||||
title: 'TestiPhone',
|
||||
os: 'iOS',
|
||||
logEntries: [],
|
||||
screenshotHandle: null,
|
||||
});
|
||||
const client = generateClientFromDevice(selectedDevice, 'testapp1');
|
||||
@@ -563,7 +551,6 @@ test('test processStore function for notifications for unselected device', async
|
||||
deviceType: 'emulator',
|
||||
title: 'TestiPhone',
|
||||
os: 'iOS',
|
||||
logEntries: [],
|
||||
screenshotHandle: null,
|
||||
});
|
||||
const unselectedDevice = new ArchivedDevice({
|
||||
@@ -571,7 +558,6 @@ test('test processStore function for notifications for unselected device', async
|
||||
deviceType: 'emulator',
|
||||
title: 'TestiPhone',
|
||||
os: 'iOS',
|
||||
logEntries: [],
|
||||
screenshotHandle: null,
|
||||
});
|
||||
|
||||
@@ -619,7 +605,6 @@ test('test processStore function for selected plugins', async () => {
|
||||
deviceType: 'emulator',
|
||||
title: 'TestiPhone',
|
||||
os: 'iOS',
|
||||
logEntries: [],
|
||||
screenshotHandle: null,
|
||||
});
|
||||
|
||||
@@ -670,7 +655,6 @@ test('test processStore function for no selected plugins', async () => {
|
||||
deviceType: 'emulator',
|
||||
title: 'TestiPhone',
|
||||
os: 'iOS',
|
||||
logEntries: [],
|
||||
screenshotHandle: null,
|
||||
});
|
||||
const client = generateClientFromDevice(selectedDevice, 'app');
|
||||
@@ -1021,7 +1005,6 @@ test('test determinePluginsToProcess to ignore archived clients', async () => {
|
||||
deviceType: 'emulator',
|
||||
title: 'TestiPhone',
|
||||
os: 'iOS',
|
||||
logEntries: [],
|
||||
screenshotHandle: null,
|
||||
});
|
||||
const logger = {
|
||||
|
||||
@@ -326,7 +326,6 @@ async function addSaltToDeviceSerial({
|
||||
pluginStates,
|
||||
pluginNotification,
|
||||
statusUpdate,
|
||||
selectedPlugins,
|
||||
pluginStates2,
|
||||
devicePluginStates,
|
||||
}: AddSaltToDeviceSerialOptions): Promise<ExportType> {
|
||||
@@ -337,11 +336,6 @@ async function addSaltToDeviceSerial({
|
||||
deviceType: device.deviceType,
|
||||
title: device.title,
|
||||
os: device.os,
|
||||
logEntries: selectedPlugins.includes('DeviceLogs')
|
||||
? device.getLogs(
|
||||
new Date(new Date().getTime() - 1000 * 60 * 10), // Last 10 mins of logs
|
||||
)
|
||||
: [],
|
||||
screenshotHandle: deviceScreenshot,
|
||||
});
|
||||
statusUpdate &&
|
||||
@@ -776,18 +770,13 @@ export function importDataToStore(source: string, data: string, store: Store) {
|
||||
if (device == null) {
|
||||
return;
|
||||
}
|
||||
const {serial, deviceType, title, os, logs} = device;
|
||||
const {serial, deviceType, title, os} = device;
|
||||
|
||||
const archivedDevice = new ArchivedDevice({
|
||||
serial,
|
||||
deviceType,
|
||||
title,
|
||||
os,
|
||||
logEntries: logs
|
||||
? logs.map((l) => {
|
||||
return {...l, date: new Date(l.date)};
|
||||
})
|
||||
: [],
|
||||
screenshotHandle: deviceScreenshot,
|
||||
source,
|
||||
supportRequestDetails,
|
||||
|
||||
@@ -19,16 +19,10 @@ export const stateSanitizer = (state: State) => {
|
||||
connections: {
|
||||
...state.connections,
|
||||
devices: devices.map<DeviceExport>((device) => {
|
||||
return {
|
||||
...device.toJSON(),
|
||||
logs: [],
|
||||
} as any;
|
||||
return device.toJSON() as any;
|
||||
}),
|
||||
selectedDevice: selectedDevice
|
||||
? ({
|
||||
...selectedDevice.toJSON(),
|
||||
logs: [],
|
||||
} as any)
|
||||
? (selectedDevice.toJSON() as any)
|
||||
: null,
|
||||
},
|
||||
};
|
||||
|
||||
Reference in New Issue
Block a user