Setting up Persist Storage for LRU Plugins
Summary: - Change policy to show plugins to LRU (least recently used) - Add persist storage to store LRU plugins Reviewed By: danielbuechele Differential Revision: D16917951 fbshipit-source-id: 8ea7b2f15e06db51209953818f465a05e24c38c4
This commit is contained in:
committed by
Facebook Github Bot
parent
afd7634fd6
commit
007a29805a
@@ -100,6 +100,7 @@ export default class Client extends EventEmitter {
|
|||||||
sdkVersion: number;
|
sdkVersion: number;
|
||||||
messageIdCounter: number;
|
messageIdCounter: number;
|
||||||
plugins: Plugins;
|
plugins: Plugins;
|
||||||
|
lessPlugins: Plugins;
|
||||||
showAllPlugins: boolean;
|
showAllPlugins: boolean;
|
||||||
connection: RSocketClientSocket<any, any> | null | undefined;
|
connection: RSocketClientSocket<any, any> | null | undefined;
|
||||||
responder: Partial<Responder<any, any>>;
|
responder: Partial<Responder<any, any>>;
|
||||||
@@ -117,7 +118,7 @@ export default class Client extends EventEmitter {
|
|||||||
reject: (err: Error) => void;
|
reject: (err: Error) => void;
|
||||||
metadata: RequestMetadata;
|
metadata: RequestMetadata;
|
||||||
// eslint-disable-next-line prettier/prettier
|
// eslint-disable-next-line prettier/prettier
|
||||||
}
|
}
|
||||||
>;
|
>;
|
||||||
|
|
||||||
constructor(
|
constructor(
|
||||||
|
|||||||
@@ -22,6 +22,7 @@ export type State = {
|
|||||||
userPreferredDevice: null | string;
|
userPreferredDevice: null | string;
|
||||||
userPreferredPlugin: null | string;
|
userPreferredPlugin: null | string;
|
||||||
userPreferredApp: null | string;
|
userPreferredApp: null | string;
|
||||||
|
userLRUPlugins: Map<string, Array<string>>;
|
||||||
error: null | string;
|
error: null | string;
|
||||||
clients: Array<Client>;
|
clients: Array<Client>;
|
||||||
uninitializedClients: Array<{
|
uninitializedClients: Array<{
|
||||||
@@ -32,6 +33,8 @@ export type State = {
|
|||||||
deepLinkPayload: null | string;
|
deepLinkPayload: null | string;
|
||||||
};
|
};
|
||||||
|
|
||||||
|
const MAX_MINIMUM_PLUGINS = 5;
|
||||||
|
|
||||||
export type Action =
|
export type Action =
|
||||||
| {
|
| {
|
||||||
type: 'UNREGISTER_DEVICES';
|
type: 'UNREGISTER_DEVICES';
|
||||||
@@ -110,6 +113,7 @@ const INITAL_STATE: State = {
|
|||||||
userPreferredDevice: null,
|
userPreferredDevice: null,
|
||||||
userPreferredPlugin: null,
|
userPreferredPlugin: null,
|
||||||
userPreferredApp: null,
|
userPreferredApp: null,
|
||||||
|
userLRUPlugins: new Map(),
|
||||||
error: null,
|
error: null,
|
||||||
clients: [],
|
clients: [],
|
||||||
uninitializedClients: [],
|
uninitializedClients: [],
|
||||||
@@ -211,11 +215,21 @@ const reducer = (state: State = INITAL_STATE, action: Action): State => {
|
|||||||
performance.mark(`activePlugin-${selectedPlugin}`);
|
performance.mark(`activePlugin-${selectedPlugin}`);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
const LRUPlugins =
|
||||||
|
state.userLRUPlugins[selectedApp || state.userPreferredApp] || [];
|
||||||
|
const idxLRU = LRUPlugins.indexOf(selectedPlugin);
|
||||||
|
if (idxLRU > 0) {
|
||||||
|
LRUPlugins.splice(idxLRU, 1);
|
||||||
|
}
|
||||||
|
LRUPlugins.unshift(selectedPlugin);
|
||||||
|
LRUPlugins.splice(MAX_MINIMUM_PLUGINS);
|
||||||
|
|
||||||
return {
|
return {
|
||||||
...state,
|
...state,
|
||||||
...payload,
|
...payload,
|
||||||
userPreferredApp: selectedApp || state.userPreferredApp,
|
userPreferredApp: selectedApp || state.userPreferredApp,
|
||||||
userPreferredPlugin: selectedPlugin,
|
userPreferredPlugin: selectedPlugin,
|
||||||
|
userLRUPlugins: {...state.userLRUPlugins, [selectedApp]: LRUPlugins},
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
case 'SELECT_USER_PREFERRED_PLUGIN': {
|
case 'SELECT_USER_PREFERRED_PLUGIN': {
|
||||||
@@ -224,9 +238,19 @@ const reducer = (state: State = INITAL_STATE, action: Action): State => {
|
|||||||
}
|
}
|
||||||
case 'NEW_CLIENT': {
|
case 'NEW_CLIENT': {
|
||||||
const {payload} = action;
|
const {payload} = action;
|
||||||
const {userPreferredApp, userPreferredPlugin} = state;
|
const {userPreferredApp, userPreferredPlugin, userLRUPlugins} = state;
|
||||||
let {selectedApp, selectedPlugin} = state;
|
let {selectedApp, selectedPlugin} = state;
|
||||||
|
|
||||||
|
const lessPlugins = userLRUPlugins[payload.id];
|
||||||
|
if (lessPlugins) {
|
||||||
|
payload.lessPlugins = lessPlugins.concat(
|
||||||
|
payload.plugins.filter(p => !lessPlugins.includes(p)),
|
||||||
|
);
|
||||||
|
} else {
|
||||||
|
payload.lessPlugins = payload.plugins;
|
||||||
|
}
|
||||||
|
payload.lessPlugins = payload.lessPlugins.slice(0, MAX_MINIMUM_PLUGINS);
|
||||||
|
|
||||||
if (
|
if (
|
||||||
userPreferredApp &&
|
userPreferredApp &&
|
||||||
userPreferredPlugin &&
|
userPreferredPlugin &&
|
||||||
@@ -247,6 +271,10 @@ const reducer = (state: State = INITAL_STATE, action: Action): State => {
|
|||||||
c.client.appName !== payload.query.app
|
c.client.appName !== payload.query.app
|
||||||
);
|
);
|
||||||
}),
|
}),
|
||||||
|
userLRUPlugins: {
|
||||||
|
...state.userLRUPlugins,
|
||||||
|
[payload.id]: payload.lessPlugins,
|
||||||
|
},
|
||||||
selectedApp,
|
selectedApp,
|
||||||
selectedPlugin,
|
selectedPlugin,
|
||||||
};
|
};
|
||||||
@@ -348,6 +376,7 @@ const reducer = (state: State = INITAL_STATE, action: Action): State => {
|
|||||||
clients: state.clients.map((client: Client) => {
|
clients: state.clients.map((client: Client) => {
|
||||||
if (client.id === payload) {
|
if (client.id === payload) {
|
||||||
client.showAllPlugins = !client.showAllPlugins;
|
client.showAllPlugins = !client.showAllPlugins;
|
||||||
|
client.lessPlugins = state.userLRUPlugins[payload];
|
||||||
}
|
}
|
||||||
return client;
|
return client;
|
||||||
}),
|
}),
|
||||||
|
|||||||
@@ -71,6 +71,7 @@ export default combineReducers<State, Actions>({
|
|||||||
'userPreferredDevice',
|
'userPreferredDevice',
|
||||||
'userPreferredPlugin',
|
'userPreferredPlugin',
|
||||||
'userPreferredApp',
|
'userPreferredApp',
|
||||||
|
'userLRUPlugins',
|
||||||
],
|
],
|
||||||
},
|
},
|
||||||
connections,
|
connections,
|
||||||
|
|||||||
Reference in New Issue
Block a user