Skip to content

Commit 27a6f53

Browse files
authored
Merge pull request #1425 from RedisInsight/fe/feature/RI-3804_optimize-ls
#RI-3804 - optimize LS instances data
2 parents 51cc79c + e9d4b94 commit 27a6f53

File tree

19 files changed

+181
-111
lines changed

19 files changed

+181
-111
lines changed

redisinsight/ui/src/pages/browser/components/key-tree/KeyTree.tsx

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,11 @@
1-
import React, { forwardRef, useCallback, useEffect, useImperativeHandle, useRef, useState, useTransition } from 'react'
1+
import React, { forwardRef, useCallback, useEffect, useImperativeHandle, useState, useTransition } from 'react'
22
import cx from 'classnames'
33
import { EuiResizableContainer } from '@elastic/eui'
44
import { useDispatch, useSelector } from 'react-redux'
55

66
import {
77
appContextBrowserTree,
8+
appContextDbConfig,
89
setBrowserTreeNodesOpen,
910
setBrowserTreeSelectedLeaf
1011
} from 'uiSrc/slices/app/context'
@@ -39,7 +40,8 @@ const KeyTree = forwardRef((props: Props, ref) => {
3940
const firstPanelId = 'tree'
4041
const secondPanelId = 'keys'
4142

42-
const { delimiter, panelSizes, openNodes, selectedLeaf } = useSelector(appContextBrowserTree)
43+
const { panelSizes, openNodes, selectedLeaf } = useSelector(appContextBrowserTree)
44+
const { treeViewDelimiter: delimiter = '' } = useSelector(appContextDbConfig)
4345

4446
const [,startTransition] = useTransition()
4547

redisinsight/ui/src/pages/browser/components/key-tree/KeyTreeDelimiter/KeyTreeDelimiter.spec.tsx

Lines changed: 0 additions & 32 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,6 @@ import React from 'react'
33
import { instance, mock } from 'ts-mockito'
44
import { DEFAULT_DELIMITER } from 'uiSrc/constants'
55
import { setBrowserTreeDelimiter } from 'uiSrc/slices/app/context'
6-
import { localStorageService } from 'uiSrc/services'
76
import {
87
cleanup,
98
clearStoreActions,
@@ -57,37 +56,6 @@ describe('KeyTreeDelimiter', () => {
5756
expect(screen.getByTestId(DELIMITER_INPUT)).toBeInTheDocument()
5857
})
5958

60-
it('"setBrowserTreeDelimiter" should be called with value for LocalStorage after render', async () => {
61-
jest.useFakeTimers()
62-
const localStorageValue = 'test'
63-
localStorageService.get = jest.fn().mockReturnValue(localStorageValue)
64-
65-
render(<KeyTreeDelimiter {...instance(mockedProps)} />)
66-
67-
jest.advanceTimersByTime(0)
68-
69-
const expectedActions = [setBrowserTreeDelimiter(localStorageValue)]
70-
71-
expect(clearStoreActions(store.getActions())).toEqual(
72-
clearStoreActions(expectedActions)
73-
)
74-
})
75-
76-
it('"setBrowserTreeDelimiter" should be called with DEFAULT_DELIMITER after render', async () => {
77-
jest.useFakeTimers()
78-
const localStorageValue = ''
79-
localStorageService.get = jest.fn().mockReturnValue(localStorageValue)
80-
render(<KeyTreeDelimiter {...instance(mockedProps)} />)
81-
82-
jest.advanceTimersByTime(0)
83-
84-
const expectedActions = [setBrowserTreeDelimiter(DEFAULT_DELIMITER)]
85-
86-
expect(clearStoreActions(store.getActions())).toEqual(
87-
clearStoreActions(expectedActions)
88-
)
89-
})
90-
9159
it('"setBrowserTreeDelimiter" should be called after Apply change delimiter', async () => {
9260
const value = 'val'
9361
render(<KeyTreeDelimiter {...instance(mockedProps)} />)

redisinsight/ui/src/pages/browser/components/key-tree/KeyTreeDelimiter/KeyTreeDelimiter.tsx

Lines changed: 4 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -1,15 +1,14 @@
1-
import React, { useEffect, useState } from 'react'
1+
import React, { useState } from 'react'
22
import cx from 'classnames'
33
import { useDispatch, useSelector } from 'react-redux'
44
import { useParams } from 'react-router-dom'
55
import { EuiIcon, EuiPopover } from '@elastic/eui'
66

77
import { replaceSpaces } from 'uiSrc/utils'
8-
import { localStorageService } from 'uiSrc/services'
98
import { sendEventTelemetry, TelemetryEvent } from 'uiSrc/telemetry'
109
import InlineItemEditor from 'uiSrc/components/inline-item-editor'
11-
import { BrowserStorageItem, DEFAULT_DELIMITER } from 'uiSrc/constants'
12-
import { appContextBrowserTree, setBrowserTreeDelimiter } from 'uiSrc/slices/app/context'
10+
import { DEFAULT_DELIMITER } from 'uiSrc/constants'
11+
import { appContextDbConfig, setBrowserTreeDelimiter } from 'uiSrc/slices/app/context'
1312

1413
import styles from './styles.module.scss'
1514

@@ -19,24 +18,14 @@ export interface Props {
1918
const MAX_DELIMITER_LENGTH = 5
2019
const KeyTreeDelimiter = ({ loading }: Props) => {
2120
const { instanceId = '' } = useParams<{ instanceId: string }>()
22-
const { delimiter = '' } = useSelector(appContextBrowserTree)
21+
const { treeViewDelimiter: delimiter = '' } = useSelector(appContextDbConfig)
2322
const [isPopoverOpen, setIsPopoverOpen] = useState(false)
2423

2524
const dispatch = useDispatch()
2625

2726
const onButtonClick = () => setIsPopoverOpen((isPopoverOpen) => !isPopoverOpen)
2827
const closePopover = () => setIsPopoverOpen(false)
2928

30-
useEffect(() => {
31-
const delimiterStorage = localStorageService.get(BrowserStorageItem.treeViewDelimiter + instanceId)
32-
|| delimiter
33-
|| DEFAULT_DELIMITER
34-
35-
setTimeout(() => {
36-
dispatch(setBrowserTreeDelimiter(delimiterStorage))
37-
}, 0)
38-
}, [])
39-
4029
const button = (
4130
<div
4231
onClick={onButtonClick}

redisinsight/ui/src/pages/databaseAnalysis/components/header/Header.tsx

Lines changed: 4 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -15,11 +15,9 @@ import { useDispatch, useSelector } from 'react-redux'
1515
import { useParams } from 'react-router-dom'
1616

1717
import { createNewAnalysis } from 'uiSrc/slices/analytics/dbAnalysis'
18-
import { localStorageService } from 'uiSrc/services'
1918
import { numberWithSpaces } from 'uiSrc/utils/numbers'
2019
import { getApproximatePercentage } from 'uiSrc/utils/validations'
21-
import { BrowserStorageItem, DEFAULT_DELIMITER } from 'uiSrc/constants'
22-
import { appContextBrowserTree } from 'uiSrc/slices/app/context'
20+
import { appContextDbConfig } from 'uiSrc/slices/app/context'
2321
import { connectedInstanceSelector } from 'uiSrc/slices/instances/instances'
2422
import { ConnectionType } from 'uiSrc/slices/interfaces'
2523
import AnalyticsTabs from 'uiSrc/components/analytics-tabs'
@@ -56,11 +54,7 @@ const Header = (props: Props) => {
5654
const { instanceId } = useParams<{ instanceId: string }>()
5755
const dispatch = useDispatch()
5856

59-
const { delimiter = '' } = useSelector(appContextBrowserTree)
60-
61-
const delimiterStorage = localStorageService.get(BrowserStorageItem.treeViewDelimiter + instanceId)
62-
|| delimiter
63-
|| DEFAULT_DELIMITER
57+
const { treeViewDelimiter: delimiter = '' } = useSelector(appContextDbConfig)
6458

6559
const analysisOptions: EuiSuperSelectOption<any>[] = items.map((item) => {
6660
const { createdAt, id } = item
@@ -80,7 +74,7 @@ const Header = (props: Props) => {
8074
databaseId: instanceId,
8175
}
8276
})
83-
dispatch(createNewAnalysis(instanceId, delimiterStorage))
77+
dispatch(createNewAnalysis(instanceId, delimiter))
8478
}
8579

8680
return (
@@ -135,7 +129,7 @@ const Header = (props: Props) => {
135129
)}
136130
<EuiFlexItem grow={false}>
137131
<EuiFlexGroup gutterSize="none" alignItems="center" responsive={false}>
138-
<EuiFlexItem style={{ overflow: 'hidden' }}>
132+
<EuiFlexItem>
139133
<EuiButton
140134
aria-label="New reports"
141135
fill

redisinsight/ui/src/pages/home/HomePage.tsx

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@ import {
77
resetDataRedisCluster,
88
resetInstancesRedisCluster,
99
} from 'uiSrc/slices/instances/cluster'
10-
import { setTitle } from 'uiSrc/utils'
10+
import { optimizeLSInstances, setTitle } from 'uiSrc/utils'
1111
import { PageHeader } from 'uiSrc/components'
1212
import { BrowserStorageItem } from 'uiSrc/constants'
1313
import { Instance } from 'uiSrc/slices/interfaces'
@@ -93,6 +93,9 @@ const HomePage = () => {
9393
name: TelemetryPageView.DATABASES_LIST_PAGE
9494
})
9595
}
96+
if (instances.length && !isPageViewSent) {
97+
optimizeLSInstances(instances)
98+
}
9699
}, [instances, analyticsIdentified, isPageViewSent, isChangedInstance])
97100

98101
useEffect(() => {
@@ -168,6 +171,10 @@ const HomePage = () => {
168171
dispatch(setEditedInstance(null))
169172
setEditDialogIsOpen(false)
170173
}
174+
175+
instances.forEach((instance) => {
176+
localStorageService.remove(BrowserStorageItem.dbConfig + instance.id)
177+
})
171178
}
172179

173180
const onResize = ({ width: innerWidth }: { width: number }) => {

redisinsight/ui/src/pages/instance/InstancePage.tsx

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,7 @@ import {
1515
appContextSelector,
1616
setAppContextConnectedInstanceId,
1717
setAppContextInitialState,
18+
setDbConfig,
1819
} from 'uiSrc/slices/app/context'
1920
import { resetPatternKeysData } from 'uiSrc/slices/browser/keys'
2021
import { BrowserStorageItem } from 'uiSrc/constants'
@@ -78,6 +79,7 @@ const InstancePage = ({ routes = [] }: Props) => {
7879
}
7980

8081
dispatch(setAppContextConnectedInstanceId(connectionInstanceId))
82+
dispatch(setDbConfig(localStorageService.get(BrowserStorageItem.dbConfig + connectionInstanceId)))
8183
}, [])
8284

8385
useEffect(() => () => {

redisinsight/ui/src/pages/slowLog/SlowLogPage.tsx

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,7 @@ import { AutoSizer } from 'react-virtualized'
1515
import { DEFAULT_SLOWLOG_MAX_LEN } from 'uiSrc/constants'
1616
import { DATE_FORMAT } from 'uiSrc/pages/slowLog/components/SlowLogTable/SlowLogTable'
1717
import { convertNumberByUnits } from 'uiSrc/pages/slowLog/utils'
18+
import { appContextDbConfig } from 'uiSrc/slices/app/context'
1819
import { appAnalyticsInfoSelector } from 'uiSrc/slices/app/info'
1920
import { connectedInstanceSelector } from 'uiSrc/slices/instances/instances'
2021
import { ConnectionType } from 'uiSrc/slices/interfaces'
@@ -51,7 +52,8 @@ const countOptions: EuiSuperSelectOption<string>[] = [
5152

5253
const SlowLogPage = () => {
5354
const { connectionType, name: connectedInstanceName, db } = useSelector(connectedInstanceSelector)
54-
const { data, loading, durationUnit, config } = useSelector(slowLogSelector)
55+
const { data, loading, config } = useSelector(slowLogSelector)
56+
const { slowLogDurationUnit: durationUnit } = useSelector(appContextDbConfig)
5557
const { slowlogLogSlowerThan = 0, slowlogMaxLen } = useSelector(slowLogConfigSelector)
5658
const { identified: analyticsIdentified } = useSelector(appAnalyticsInfoSelector)
5759
const { viewTab } = useSelector(analyticsSettingsSelector)

redisinsight/ui/src/pages/slowLog/components/SlowLogConfig/SlowLogConfig.tsx

Lines changed: 4 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -21,9 +21,8 @@ import {
2121
DURATION_UNITS,
2222
MINUS_ONE,
2323
} from 'uiSrc/constants'
24+
import { appContextDbConfig } from 'uiSrc/slices/app/context'
2425
import { ConnectionType } from 'uiSrc/slices/interfaces'
25-
import { ConfigDBStorageItem } from 'uiSrc/constants/storage'
26-
import { setDBConfigStorageField } from 'uiSrc/services'
2726
import { patchSlowLogConfigAction, slowLogConfigSelector, slowLogSelector } from 'uiSrc/slices/analytics/slowlog'
2827
import { errorValidateNegativeInteger, validateNumber } from 'uiSrc/utils'
2928
import { connectedInstanceSelector } from 'uiSrc/slices/instances/instances'
@@ -40,13 +39,14 @@ const SlowLogConfig = ({ closePopover, onRefresh }: Props) => {
4039
const options = DURATION_UNITS
4140
const { instanceId } = useParams<{ instanceId: string }>()
4241
const { connectionType } = useSelector(connectedInstanceSelector)
43-
const { loading, durationUnit: durationUnitStore } = useSelector(slowLogSelector)
42+
const { loading } = useSelector(slowLogSelector)
43+
const { slowLogDurationUnit } = useSelector(appContextDbConfig)
4444
const {
4545
slowlogMaxLen = DEFAULT_SLOWLOG_MAX_LEN,
4646
slowlogLogSlowerThan = DEFAULT_SLOWLOG_SLOWER_THAN,
4747
} = useSelector(slowLogConfigSelector)
4848

49-
const [durationUnit, setDurationUnit] = useState(durationUnitStore ?? DEFAULT_SLOWLOG_DURATION_UNIT)
49+
const [durationUnit, setDurationUnit] = useState(slowLogDurationUnit ?? DEFAULT_SLOWLOG_DURATION_UNIT)
5050
const [maxLen, setMaxLen] = useState(`${slowlogMaxLen}`)
5151

5252
const [slowerThan, setSlowerThan] = useState(slowlogLogSlowerThan !== MINUS_ONE
@@ -96,8 +96,6 @@ const SlowLogConfig = ({ closePopover, onRefresh }: Props) => {
9696
}
9797

9898
const onSuccess = () => {
99-
setDBConfigStorageField(instanceId, ConfigDBStorageItem.slowLogDurationUnit, durationUnit)
100-
10199
onRefresh(maxLen ? toNumber(maxLen) : DEFAULT_SLOWLOG_MAX_LEN)
102100
closePopover()
103101
}

redisinsight/ui/src/services/storage.ts

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,10 @@ class StorageService {
2626
return null
2727
}
2828

29+
getAll() {
30+
return this.storage
31+
}
32+
2933
set(itemName: string = '', item: any) {
3034
try {
3135
if (isObjectLike(item)) {

redisinsight/ui/src/slices/analytics/slowlog.ts

Lines changed: 10 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,11 @@
11
import { createSlice, PayloadAction } from '@reduxjs/toolkit'
22
import { AxiosError } from 'axios'
3-
import { ApiEndpoints, DEFAULT_SLOWLOG_DURATION_UNIT, DurationUnits } from 'uiSrc/constants'
4-
import { apiService, getDBConfigStorageField } from 'uiSrc/services'
3+
import { ApiEndpoints, DurationUnits } from 'uiSrc/constants'
4+
import { apiService } from 'uiSrc/services'
5+
import { setSlowLogUnits } from 'uiSrc/slices/app/context'
56
import { addErrorNotification } from 'uiSrc/slices/app/notifications'
67
import { StateSlowLog } from 'uiSrc/slices/interfaces/analytics'
7-
import { ConfigDBStorageItem } from 'uiSrc/constants/storage'
8-
import { getApiErrorMessage, getUrl, isStatusSuccessful, Nullable } from 'uiSrc/utils'
8+
import { getApiErrorMessage, getUrl, isStatusSuccessful } from 'uiSrc/utils'
99
import { SlowLog, SlowLogConfig } from 'apiSrc/modules/slow-log/models'
1010

1111
import { AppDispatch, RootState } from '../store'
@@ -15,7 +15,6 @@ export const initialState: StateSlowLog = {
1515
error: '',
1616
data: [],
1717
lastRefreshTime: null,
18-
durationUnit: DurationUnits.microSeconds,
1918
config: null
2019
}
2120

@@ -29,11 +28,10 @@ const slowLogSlice = createSlice({
2928
},
3029
getSlowLogsSuccess: (
3130
state,
32-
{ payload: [data, durationUnit] }: PayloadAction<[SlowLog[], DurationUnits]>
31+
{ payload: data }: PayloadAction<SlowLog[]>
3332
) => {
3433
state.loading = false
3534
state.data = data
36-
state.durationUnit = durationUnit
3735
state.lastRefreshTime = Date.now()
3836
},
3937
getSlowLogsError: (state, { payload }) => {
@@ -56,14 +54,10 @@ const slowLogSlice = createSlice({
5654
},
5755
getSlowLogConfigSuccess: (
5856
state,
59-
{ payload: [data, durationUnit] }: PayloadAction<[SlowLogConfig, Nullable<DurationUnits> ]>
57+
{ payload: data }: PayloadAction<SlowLogConfig>
6058
) => {
6159
state.loading = false
6260
state.config = data
63-
64-
if (durationUnit) {
65-
state.durationUnit = durationUnit
66-
}
6761
},
6862
getSlowLogConfigError: (state, { payload }) => {
6963
state.loading = false
@@ -113,13 +107,7 @@ export function fetchSlowLogsAction(
113107
)
114108

115109
if (isStatusSuccessful(status)) {
116-
dispatch(
117-
getSlowLogsSuccess([
118-
data,
119-
getDBConfigStorageField(instanceId, ConfigDBStorageItem.slowLogDurationUnit)
120-
|| DEFAULT_SLOWLOG_DURATION_UNIT
121-
])
122-
)
110+
dispatch(getSlowLogsSuccess(data))
123111

124112
onSuccessAction?.(data)
125113
}
@@ -183,7 +171,7 @@ export function getSlowLogConfigAction(
183171
)
184172

185173
if (isStatusSuccessful(status)) {
186-
dispatch(getSlowLogConfigSuccess([data, null]))
174+
dispatch(getSlowLogConfigSuccess(data))
187175

188176
onSuccessAction?.()
189177
}
@@ -218,7 +206,8 @@ export function patchSlowLogConfigAction(
218206
)
219207

220208
if (isStatusSuccessful(status)) {
221-
dispatch(getSlowLogConfigSuccess([data, durationUnit]))
209+
dispatch(getSlowLogConfigSuccess(data))
210+
dispatch(setSlowLogUnits(durationUnit))
222211

223212
onSuccessAction?.()
224213
}

0 commit comments

Comments
 (0)