-
-
Notifications
You must be signed in to change notification settings - Fork 4.7k
ref(feedback): Refactor feedback query keys #112552
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: master
Are you sure you want to change the base?
Changes from all commits
32f3553
01d20c8
a139c1c
44e0719
2f4619f
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -1,19 +1,26 @@ | ||
| import {useCallback} from 'react'; | ||
|
|
||
| import {useFeedbackCache} from 'sentry/components/feedback/useFeedbackCache'; | ||
| import {useInfiniteFeedbackListQueryOptions} from 'sentry/components/feedback/useFeedbackListQueryOptions'; | ||
| import {useFeedbackQueryKeys} from 'sentry/components/feedback/useFeedbackQueryKeys'; | ||
| import {useQueryClient} from 'sentry/utils/queryClient'; | ||
| import {useOrganization} from 'sentry/utils/useOrganization'; | ||
|
|
||
| export function useRefetchFeedbackList() { | ||
| const queryClient = useQueryClient(); | ||
| const {listQueryKey, resetListHeadTime} = useFeedbackQueryKeys(); | ||
| const organization = useOrganization(); | ||
| const {listHeadTime, resetListHeadTime} = useFeedbackQueryKeys(); | ||
| const listQueryOptions = useInfiniteFeedbackListQueryOptions({ | ||
| listHeadTime, | ||
| organization, | ||
| }); | ||
| const {invalidateListCache} = useFeedbackCache(); | ||
|
|
||
| const refetchFeedbackList = useCallback(() => { | ||
| queryClient.invalidateQueries({queryKey: listQueryKey}); | ||
| queryClient.invalidateQueries({queryKey: listQueryOptions.queryKey}); | ||
| resetListHeadTime(); | ||
| invalidateListCache(); | ||
| }, [queryClient, listQueryKey, resetListHeadTime, invalidateListCache]); | ||
| }, [queryClient, listQueryOptions.queryKey, resetListHeadTime, invalidateListCache]); | ||
|
|
||
| return {refetchFeedbackList}; | ||
| } |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -1,25 +1,33 @@ | ||
| import {useEffect, useState} from 'react'; | ||
| import {useQuery} from '@tanstack/react-query'; | ||
|
|
||
| import type {ApiQueryKey} from 'sentry/utils/queryClient'; | ||
| import {useApiQuery} from 'sentry/utils/queryClient'; | ||
| import {parseQueryKey} from 'sentry/utils/api/apiQueryKey'; | ||
| import {useOrganization} from 'sentry/utils/useOrganization'; | ||
|
|
||
| import {usePrefetchFeedbackListQueryOptions} from './useFeedbackListQueryOptions'; | ||
|
|
||
| interface Props { | ||
| listPrefetchQueryKey: ApiQueryKey | undefined; | ||
| listHeadTime: number; | ||
| } | ||
|
|
||
| const POLLING_INTERVAL_MS = 10_000; | ||
|
|
||
| export function useFeedbackHasNewItems({listPrefetchQueryKey}: Props) { | ||
| export function useFeedbackHasNewItems({listHeadTime}: Props) { | ||
| const organization = useOrganization(); | ||
| const listPrefetchQueryOptions = usePrefetchFeedbackListQueryOptions({ | ||
| listHeadTime, | ||
| organization, | ||
| }); | ||
|
|
||
| const [foundData, setFoundData] = useState(false); | ||
|
|
||
| const {data} = useApiQuery<unknown[]>( | ||
| listPrefetchQueryKey ?? ([''] as unknown as ApiQueryKey), | ||
| { | ||
| refetchInterval: POLLING_INTERVAL_MS, | ||
| staleTime: 0, | ||
| enabled: Boolean(listPrefetchQueryKey) && !foundData, | ||
| } | ||
| ); | ||
| const {statsPeriod} = | ||
| parseQueryKey(listPrefetchQueryOptions.queryKey).options?.query ?? {}; | ||
| const {data} = useQuery({ | ||
| ...listPrefetchQueryOptions, | ||
| refetchInterval: POLLING_INTERVAL_MS, | ||
| enabled: statsPeriod && !foundData, | ||
|
Comment on lines
+24
to
+29
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Bug: The Suggested FixThe logic for the Prompt for AI Agent |
||
| }); | ||
|
Comment on lines
+26
to
+30
Member
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. The idea here is that we have stored a timestamp That |
||
|
|
||
| useEffect(() => { | ||
| // Once we found something, no need to keep polling. | ||
|
|
@@ -29,7 +37,7 @@ export function useFeedbackHasNewItems({listPrefetchQueryKey}: Props) { | |
| useEffect(() => { | ||
| // New key, start polling again | ||
| setFoundData(false); | ||
| }, [listPrefetchQueryKey]); | ||
| }, [listHeadTime]); | ||
|
|
||
| return Boolean(data?.length); | ||
| } | ||
Uh oh!
There was an error while loading. Please reload this page.