📈 Open source, privacy-first web analytics — a cookie-less Google Analytics alternative with built-in error tracking and performance monitoring. Self-host it or use our cloud. Get started for free!
TypeScript chartsclickhousedockergdprgoogle-analyticsmetricsmonitoringmysqlnestjsprivacyredisself-hostedselfhostedstatisticstailwindcssweb-analyticswebanalyticswebsite
Get rid of userflow cache
Blue Mouse3d0c0be8e44b
diff --git a/web/app/lib/constants/index.ts b/web/app/lib/constants/index.tsindex b634693ee..44fb09caf 100644--- a/web/app/lib/constants/index.ts+++ b/web/app/lib/constants/index.ts@@ -428,8 +428,6 @@ export const getProjectCacheCustomKeyPerf = (filters: any,measure: string,): string => `${from}-${to}-${timeBucket}perf${filters ? JSON.stringify(filters) : ''}-${measure}`-export const getUserFlowCacheKey = (pid: string, period: string, filters: any): string =>- `${pid}${period}userflow${filters ? JSON.stringify(filters) : ''}`export const getFunnelsCacheKey = (pid: string, funnelId: string, period: string): string =>`${pid}${funnelId}${period}funnels`export const getFunnelsCacheCustomKey = (pid: string, funnelId: string, from: string, to: string): string =>diff --git a/web/app/lib/reducers/ui/cache.ts b/web/app/lib/reducers/ui/cache.tsindex 8cface402..879e272c3 100644--- a/web/app/lib/reducers/ui/cache.ts+++ b/web/app/lib/reducers/ui/cache.ts@@ -7,10 +7,8 @@ import {LS_VIEW_PREFS_SETTING,LS_CAPTCHA_VIEW_PREFS_SETTING,getProjectCaptchaCacheKey,- getUserFlowCacheKey,isBrowser,} from 'lib/constants'-import { IUserFlow } from 'lib/models/UserFlow'import { filterInvalidViewPrefs } from 'pages/Project/View/utils/filters'const getInitialViewPrefs = (LS_VIEW: string) => {@@ -43,12 +41,6 @@ interface InitialState {rangeDate?: Date[]}} | null- userFlowAscending: {- [key: string]: IUserFlow- }- userFlowDescending: {- [key: string]: IUserFlow- }activeReferrals: any[]referralStatistics: any}@@ -61,8 +53,6 @@ const initialState: InitialState = {captchaProjectsViewPrefs: getInitialViewPrefs(LS_CAPTCHA_VIEW_PREFS_SETTING) || {},projectViewPrefs: getInitialViewPrefs(LS_VIEW_PREFS_SETTING),customEventsPrefs: {},- userFlowAscending: {},- userFlowDescending: {},activeReferrals: [],referralStatistics: {},}@@ -237,28 +227,6 @@ const cacheSlice = createSlice({},}},- setUserFlowAscending(- state,- { payload }: PayloadAction<{ pid: string; period: string; data: IUserFlow; filters: any }>,- ) {- const key = getUserFlowCacheKey(payload.pid, payload.period, payload.filters)-- state.userFlowAscending = {- ...state.userFlowAscending,- [key]: payload.data,- }- },- setUserFlowDescending(- state,- { payload }: PayloadAction<{ pid: string; period: string; data: IUserFlow; filters: any }>,- ) {- const key = getUserFlowCacheKey(payload.pid, payload.period, payload.filters)-- state.userFlowDescending = {- ...state.userFlowDescending,- [key]: payload.data,- }- },setCache(state, { payload }: PayloadAction<{ key: string; value: any }>) {const { key, value } = payloaddiff --git a/web/app/pages/Project/View/components/UserFlow.tsx b/web/app/pages/Project/View/components/UserFlow.tsxindex 8f87da9d0..af0197b64 100644--- a/web/app/pages/Project/View/components/UserFlow.tsx+++ b/web/app/pages/Project/View/components/UserFlow.tsx@@ -1,62 +1,21 @@import { useEffect, useState } from 'react'import { toast } from 'sonner'import { ResponsiveSankey } from '@nivo/sankey'-import { connect } from 'react-redux'-import { StateType, AppDispatch } from 'lib/store'-import UIActions from 'lib/reducers/ui'import { IUserFlow } from 'lib/models/UserFlow'import _isEmpty from 'lodash/isEmpty'-import { getUserFlowCacheKey } from 'lib/constants'import { getUserFlow } from 'api'import Loader from 'ui/Loader'import { Filter } from '../interfaces/traffic'import { useTranslation } from 'react-i18next'-const mapStateToProps = (state: StateType) => ({- userFlowAscendingCache: state.ui.cache.userFlowAscending,- userFlowDescendingCache: state.ui.cache.userFlowDescending,- password: state.ui.projects.password,-})--const mapDispatchToProps = (dispatch: AppDispatch) => ({- setUserFlowAscending: (data: IUserFlow, pid: string, period: string, filters: any) => {- dispatch(- UIActions.setUserFlowAscending({- data,- pid,- period,- filters,- }),- )- },- setUserFlowDescending: (data: IUserFlow, pid: string, period: string, filters: any) => {- dispatch(- UIActions.setUserFlowDescending({- data,- pid,- period,- filters,- }),- )- },-})-interface UserFlowProps {pid: string- userFlowAscendingCache: {- [key: string]: IUserFlow- }- userFlowDescendingCache: {- [key: string]: IUserFlow- }period: stringtimezone: stringtimeBucket: stringfrom: stringto: stringisReversed?: boolean- setUserFlowAscending: (data: IUserFlow, id: string, pd: string, fltr: any) => void- setUserFlowDescending: (data: IUserFlow, id: string, pd: string, fltr: any) => voidfilters: Filter[]setReversed: () => voidprojectPassword?: string@@ -69,44 +28,46 @@ const UserFlow = ({from,to,timezone,- userFlowAscendingCache,- userFlowDescendingCache,filters,setReversed,isReversed,- setUserFlowAscending,- setUserFlowDescending,projectPassword,}: UserFlowProps) => {const { t } = useTranslation('common')- const key = getUserFlowCacheKey(pid, period, filters)- const userFlowAscending = userFlowAscendingCache[key]- const userFlowDescending = userFlowDescendingCache[key]const [isLoading, setIsLoading] = useState(true)+ const [userFlow, setUserFlow] = useState<{+ ascending: IUserFlow+ descending: IUserFlow+ } | null>(null)const fetchUserFlow = async () => {+ if (isLoading) {+ return+ }+setIsLoading(true)- await getUserFlow(pid, timeBucket, period, filters, from, to, timezone, projectPassword)- .then((res: { ascending: IUserFlow; descending: IUserFlow }) => {- const { ascending, descending } = res- setUserFlowAscending(ascending, pid, period, filters)- setUserFlowDescending(descending, pid, period, filters)- })- .catch((err: Error) => {- toast.error(err.message)- })- .finally(() => {- setIsLoading(false)- })+ try {+ const { ascending, descending } = await getUserFlow(+ pid,+ timeBucket,+ period,+ filters,+ from,+ to,+ timezone,+ projectPassword,+ )+ setUserFlow({ ascending, descending })+ } catch (error: any) {+ toast.error(typeof error === 'string' ? error : t('apiNotifications.somethingWentWrong'))+ } finally {+ setIsLoading(false)+ }}useEffect(() => {- if (_isEmpty(userFlowAscending) && _isEmpty(userFlowDescending)) {- fetchUserFlow()- } else if (isLoading) {- setIsLoading(false)- }+ fetchUserFlow()// eslint-disable-next-line react-hooks/exhaustive-deps}, [period, timeBucket, from, to, timezone, pid])@@ -121,8 +82,8 @@ const UserFlow = ({if (!isReversed- ? _isEmpty(userFlowAscending) || _isEmpty(userFlowAscending?.nodes) || _isEmpty(userFlowAscending?.links)- : _isEmpty(userFlowDescending) || _isEmpty(userFlowDescending?.links) || _isEmpty(userFlowDescending?.nodes)+ ? _isEmpty(userFlow?.ascending) || _isEmpty(userFlow?.ascending?.nodes) || _isEmpty(userFlow?.ascending?.links)+ : _isEmpty(userFlow?.descending) || _isEmpty(userFlow?.descending?.links) || _isEmpty(userFlow?.descending?.nodes)) {return (<>@@ -144,8 +105,8 @@ const UserFlow = ({return (<ResponsiveSankey- // @ts-ignore- data={isReversed ? userFlowDescending : userFlowAscending}+ // @ts-expect-error+ data={isReversed ? userFlow?.descending : userFlow?.ascending}margin={{top: 0,right: 0,@@ -179,14 +140,4 @@ const UserFlow = ({)}-const mergeProps = (- stateProps: ReturnType<typeof mapStateToProps>,- dispatchProps: ReturnType<typeof mapDispatchToProps>,- ownProps: ReturnType<typeof UserFlow>,-) => ({- ...ownProps,- ...stateProps,- ...dispatchProps,-})--export default connect(mapStateToProps, mapDispatchToProps, mergeProps)(UserFlow)+export default UserFlow