Store clients as Map rather than array

Summary: Refactor clients storage: array -> map. A lot of logic looks up clients by their id, which is currently done with an array.find operation, which is pretty inefficient. This diff changes it to a map, that is pretty important, as in the next diff the decoupled client message handing will need to find the client again for every message that arrives.

Reviewed By: timur-valiev

Differential Revision: D31303536

fbshipit-source-id: ca3f540a3de7665930d2354436d37cb0fbfd5546
This commit is contained in:
Michel Weststrate
2021-10-04 07:26:11 -07:00
committed by Facebook GitHub Bot
parent c9a34d3cc2
commit 026f8fc308
19 changed files with 105 additions and 123 deletions

View File

@@ -15,7 +15,6 @@ import {EventEmitter} from 'events';
import {State, Store} from '../reducers/index';
import {Logger} from '../fb-interfaces/Logger';
import Client from '../Client';
import {
getPluginBackgroundStats,
resetPluginBackgroundStatsDelta,
@@ -225,7 +224,7 @@ export default (store: Store, logger: Logger) => {
let sdkVersion: number | null = null;
if (selectedAppId) {
const client = clients.find((c: Client) => c.id === selectedAppId);
const client = clients.get(selectedAppId);
if (client) {
app = client.query.app;
sdkVersion = client.query.sdk_version || 0;