Use set instead of array to keep list of supported plugins per client
Summary: Use set instead of array to keep list of supported plugins per client. It is not used as array anyway, in most places it is used to determine whether a plugin is supported or not and it's much faster to use set for that. Reviewed By: priteshrnandgaonkar Differential Revision: D29200673 fbshipit-source-id: 5f3c404a1a668c153867d7c1b6c223941f0b3b36
This commit is contained in:
committed by
Facebook GitHub Bot
parent
280c612157
commit
fd9b5cc94d
@@ -718,7 +718,7 @@ test('test determinePluginsToProcess for mutilple clients having plugins present
|
||||
null,
|
||||
logger,
|
||||
mockStore,
|
||||
['TestPlugin', 'TestDevicePlugin'],
|
||||
new Set(['TestPlugin', 'TestDevicePlugin']),
|
||||
device1,
|
||||
);
|
||||
const client2 = new Client(
|
||||
@@ -732,7 +732,7 @@ test('test determinePluginsToProcess for mutilple clients having plugins present
|
||||
null,
|
||||
logger,
|
||||
mockStore,
|
||||
['TestDevicePlugin'],
|
||||
new Set(['TestDevicePlugin']),
|
||||
device1,
|
||||
);
|
||||
const client3 = new Client(
|
||||
@@ -746,7 +746,7 @@ test('test determinePluginsToProcess for mutilple clients having plugins present
|
||||
null,
|
||||
logger,
|
||||
mockStore,
|
||||
['TestPlugin', 'TestDevicePlugin'],
|
||||
new Set(['TestPlugin', 'TestDevicePlugin']),
|
||||
device1,
|
||||
);
|
||||
const plugins: PluginsState = {
|
||||
@@ -807,7 +807,7 @@ test('test determinePluginsToProcess for no selected plugin present in any clien
|
||||
null,
|
||||
logger,
|
||||
mockStore,
|
||||
['TestPlugin', 'TestDevicePlugin'],
|
||||
new Set(['TestPlugin', 'TestDevicePlugin']),
|
||||
device1,
|
||||
);
|
||||
const client2 = new Client(
|
||||
@@ -821,7 +821,7 @@ test('test determinePluginsToProcess for no selected plugin present in any clien
|
||||
null,
|
||||
logger,
|
||||
mockStore,
|
||||
['TestDevicePlugin'],
|
||||
new Set(['TestDevicePlugin']),
|
||||
device1,
|
||||
);
|
||||
const plugins: PluginsState = {
|
||||
@@ -863,7 +863,7 @@ test('test determinePluginsToProcess for multiple clients on same device', async
|
||||
null,
|
||||
logger,
|
||||
mockStore,
|
||||
['TestPlugin', 'TestDevicePlugin'],
|
||||
new Set(['TestPlugin', 'TestDevicePlugin']),
|
||||
device1,
|
||||
);
|
||||
const client2 = new Client(
|
||||
@@ -877,7 +877,7 @@ test('test determinePluginsToProcess for multiple clients on same device', async
|
||||
null,
|
||||
logger,
|
||||
mockStore,
|
||||
['TestDevicePlugin'],
|
||||
new Set(['TestDevicePlugin']),
|
||||
device1,
|
||||
);
|
||||
const plugins: PluginsState = {
|
||||
@@ -925,7 +925,7 @@ test('test determinePluginsToProcess for multiple clients on different device',
|
||||
null,
|
||||
logger,
|
||||
mockStore,
|
||||
['TestPlugin', 'TestDevicePlugin'],
|
||||
new Set(['TestPlugin', 'TestDevicePlugin']),
|
||||
device1,
|
||||
);
|
||||
const client2Device1 = new Client(
|
||||
@@ -939,7 +939,7 @@ test('test determinePluginsToProcess for multiple clients on different device',
|
||||
null,
|
||||
logger,
|
||||
mockStore,
|
||||
['TestDevicePlugin'],
|
||||
new Set(['TestDevicePlugin']),
|
||||
device1,
|
||||
);
|
||||
const client1Device2 = new Client(
|
||||
@@ -953,7 +953,7 @@ test('test determinePluginsToProcess for multiple clients on different device',
|
||||
null,
|
||||
logger,
|
||||
mockStore,
|
||||
['TestPlugin', 'TestDevicePlugin'],
|
||||
new Set(['TestPlugin', 'TestDevicePlugin']),
|
||||
device1,
|
||||
);
|
||||
const client2Device2 = new Client(
|
||||
@@ -967,7 +967,7 @@ test('test determinePluginsToProcess for multiple clients on different device',
|
||||
null,
|
||||
logger,
|
||||
mockStore,
|
||||
['TestDevicePlugin'],
|
||||
new Set(['TestDevicePlugin']),
|
||||
device1,
|
||||
);
|
||||
const plugins: PluginsState = {
|
||||
@@ -1039,7 +1039,7 @@ test('test determinePluginsToProcess to ignore archived clients', async () => {
|
||||
null,
|
||||
logger,
|
||||
mockStore,
|
||||
['TestPlugin', 'TestDevicePlugin'],
|
||||
new Set(['TestPlugin', 'TestDevicePlugin']),
|
||||
archivedDevice,
|
||||
);
|
||||
const archivedClient = new Client(
|
||||
@@ -1053,7 +1053,7 @@ test('test determinePluginsToProcess to ignore archived clients', async () => {
|
||||
null,
|
||||
logger,
|
||||
mockStore,
|
||||
['TestPlugin', 'TestDevicePlugin'],
|
||||
new Set(['TestPlugin', 'TestDevicePlugin']),
|
||||
archivedDevice,
|
||||
);
|
||||
const plugins: PluginsState = {
|
||||
@@ -1303,7 +1303,7 @@ test('Sandy plugins are imported properly', async () => {
|
||||
const client2 = store.getState().connections.clients[1];
|
||||
expect(client2).not.toBeFalsy();
|
||||
expect(client2).not.toBe(client);
|
||||
expect(client2.plugins).toEqual([TestPlugin.id]);
|
||||
expect(Array.from(client2.plugins)).toEqual([TestPlugin.id]);
|
||||
|
||||
expect(client.sandyPluginStates.get(TestPlugin.id)!.exportStateSync())
|
||||
.toMatchInlineSnapshot(`
|
||||
|
||||
@@ -619,11 +619,13 @@ export function determinePluginsToProcess(
|
||||
}
|
||||
const selectedFilteredPlugins = client
|
||||
? selectedPlugins.length > 0
|
||||
? client.plugins.filter((plugin) => selectedPlugins.includes(plugin))
|
||||
? Array.from(client.plugins).filter((plugin) =>
|
||||
selectedPlugins.includes(plugin),
|
||||
)
|
||||
: client.plugins
|
||||
: [];
|
||||
for (const plugin of selectedFilteredPlugins) {
|
||||
if (!client.plugins.includes(plugin)) {
|
||||
if (!client.plugins.has(plugin)) {
|
||||
// Ignore clients which doesn't support the selected plugins.
|
||||
continue;
|
||||
}
|
||||
@@ -827,7 +829,7 @@ export function importDataToStore(source: string, data: string, store: Store) {
|
||||
|
||||
clients.forEach((client: {id: string; query: ClientQuery}) => {
|
||||
const sandyPluginStates = json.pluginStates2[client.id] || {};
|
||||
const clientPlugins: Array<string> = [
|
||||
const clientPlugins: Set<string> = new Set([
|
||||
...keys
|
||||
.filter((key) => {
|
||||
const plugin = deconstructPluginKey(key);
|
||||
@@ -835,7 +837,7 @@ export function importDataToStore(source: string, data: string, store: Store) {
|
||||
})
|
||||
.map((pluginKey) => deconstructPluginKey(pluginKey).pluginName),
|
||||
...Object.keys(sandyPluginStates),
|
||||
];
|
||||
]);
|
||||
store.dispatch({
|
||||
type: 'NEW_CLIENT',
|
||||
payload: new Client(
|
||||
|
||||
@@ -352,9 +352,7 @@ function getFavoritePlugins(
|
||||
return [];
|
||||
}
|
||||
// for *imported* devices, all stored plugins are enabled
|
||||
return allPlugins.filter(
|
||||
(plugin) => client.plugins.indexOf(plugin.id) !== -1,
|
||||
);
|
||||
return allPlugins.filter((plugin) => client.plugins.has(plugin.id));
|
||||
}
|
||||
if (!enabledPlugins || !enabledPlugins.length) {
|
||||
return returnFavoredPlugins ? [] : allPlugins;
|
||||
|
||||
Reference in New Issue
Block a user