+ client: get rid of clients caching
This commit is contained in:
parent
2bc2b342eb
commit
7812ee1861
|
@ -5,27 +5,19 @@ import { addErrorToast, addSuccessToast } from './index';
|
|||
import { normalizeLogs, getParamsForClientsSearch, addClientInfo } from '../helpers/helpers';
|
||||
import { TABLE_DEFAULT_PAGE_SIZE } from '../helpers/constants';
|
||||
|
||||
// Cache clients in closure
|
||||
const getLogsWithParamsWrapper = () => {
|
||||
let clients = {};
|
||||
return async (config) => {
|
||||
const getLogsWithParams = async (config) => {
|
||||
const { older_than, filter, ...values } = config;
|
||||
const rawLogs = await apiClient.getQueryLog({ ...filter, older_than });
|
||||
const { data, oldest } = rawLogs;
|
||||
const logs = normalizeLogs(data);
|
||||
const clientsParams = getParamsForClientsSearch(logs, 'client');
|
||||
if (!Object.values(clientsParams).every(client => client in clients)) {
|
||||
clients = await apiClient.findClients(clientsParams);
|
||||
}
|
||||
const clients = await apiClient.findClients(clientsParams);
|
||||
const logsWithClientInfo = addClientInfo(logs, clients, 'client');
|
||||
|
||||
return {
|
||||
logs: logsWithClientInfo, oldest, older_than, filter, ...values,
|
||||
};
|
||||
};
|
||||
};
|
||||
|
||||
const getLogsWithParams = getLogsWithParamsWrapper();
|
||||
|
||||
export const getAdditionalLogsRequest = createAction('GET_ADDITIONAL_LOGS_REQUEST');
|
||||
export const getAdditionalLogsFailure = createAction('GET_ADDITIONAL_LOGS_FAILURE');
|
||||
|
|
|
@ -39,18 +39,13 @@ export const getStatsRequest = createAction('GET_STATS_REQUEST');
|
|||
export const getStatsFailure = createAction('GET_STATS_FAILURE');
|
||||
export const getStatsSuccess = createAction('GET_STATS_SUCCESS');
|
||||
|
||||
// Cache clients in closure
|
||||
const getStatsWrapper = () => {
|
||||
let clients = {};
|
||||
return () => async (dispatch) => {
|
||||
export const getStats = () => async (dispatch) => {
|
||||
dispatch(getStatsRequest());
|
||||
try {
|
||||
const stats = await apiClient.getStats();
|
||||
const normalizedTopClients = normalizeTopStats(stats.top_clients);
|
||||
const clientsParams = getParamsForClientsSearch(normalizedTopClients, 'name');
|
||||
if (!Object.values(clientsParams).every(client => client in clients)) {
|
||||
clients = await apiClient.findClients(clientsParams);
|
||||
}
|
||||
const clients = await apiClient.findClients(clientsParams);
|
||||
const topClientsWithInfo = addClientInfo(normalizedTopClients, clients, 'name');
|
||||
|
||||
const normalizedStats = {
|
||||
|
@ -67,9 +62,6 @@ const getStatsWrapper = () => {
|
|||
dispatch(getStatsFailure());
|
||||
}
|
||||
};
|
||||
};
|
||||
|
||||
export const getStats = getStatsWrapper();
|
||||
|
||||
export const resetStatsRequest = createAction('RESET_STATS_REQUEST');
|
||||
export const resetStatsFailure = createAction('RESET_STATS_FAILURE');
|
||||
|
|
Loading…
Reference in New Issue