-
-
Notifications
You must be signed in to change notification settings - Fork 4.3k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
ref(insights): Replace usage of
<ReleaseSeries>
in `<InsightsTimeSe…
…riesWidget>` (#86300) This reverts commit 3febd2b and extends the [original PR](#86129) It was reverted because it was causing crashes (https://sentry.sentry.io/issues/6352301875/?project=11276&referrer=github-pr-bot) due to a cache key conflict in react-query between `useQuery` and `useInfiniteQuery` ([read more about it here](https://tkdodo.eu/blog/effective-react-query-keys#caching-data)). This would happen in Sentry if you visited an insights page (which uses an "infinite" query) and then went to e.g. the issue details page (which has it's own hook [useReleaseMarkLineSeries](https://github.com/getsentry/sentry/blob/master/static/app/views/issueDetails/streamline/hooks/useReleaseMarkLineSeries.tsx#L25-L45) that uses a "normal" query). Both queries use the same cache key because infinite queries handles the `cursor` param for us (thus it not being part of the query key). I've made some additional changes to the hook: it's now moved to `app/utils` as it'll be needed in other places. it's also more generic now. From the original PR: > This will be needed for the new release bubbles feature as we will show releases on the mini widgets instead of only on fullscreen. Using `<ReleaseSeries>` renderer will cause duplicate requests to the API. ref #85779
- Loading branch information
Showing
13 changed files
with
199 additions
and
30 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,75 @@ | ||
import {useEffect} from 'react'; | ||
|
||
import {normalizeDateTimeParams} from 'sentry/components/organizations/pageFilters/parse'; | ||
import {useInfiniteApiQuery} from 'sentry/utils/queryClient'; | ||
import useOrganization from 'sentry/utils/useOrganization'; | ||
|
||
interface ReleaseMetaBasic { | ||
date: string; | ||
version: string; | ||
} | ||
|
||
interface UseReleaseStatsParams { | ||
datetime: Parameters<typeof normalizeDateTimeParams>[0]; | ||
environments: readonly string[]; | ||
projects: readonly number[]; | ||
|
||
/** | ||
* Max number of pages to fetch. Default is 10 pages, which should be | ||
* sufficient to fetch "all" releases. | ||
*/ | ||
maxPages?: number; | ||
} | ||
|
||
/** | ||
* This is intended to fetch "all" releases, we have a default limit of | ||
* 10 pages (of 1000 results) to be slightly cautious. | ||
*/ | ||
export function useReleaseStats( | ||
{datetime, environments, projects, maxPages = 10}: UseReleaseStatsParams, | ||
queryOptions: {staleTime: number} = {staleTime: Infinity} | ||
) { | ||
const organization = useOrganization(); | ||
|
||
const { | ||
isLoading, | ||
isFetching, | ||
fetchNextPage, | ||
hasNextPage, | ||
isPending, | ||
isError, | ||
error, | ||
data, | ||
} = useInfiniteApiQuery<ReleaseMetaBasic[]>({ | ||
queryKey: [ | ||
`/organizations/${organization.slug}/releases/stats/`, | ||
{ | ||
query: { | ||
environment: environments, | ||
project: projects, | ||
...normalizeDateTimeParams(datetime), | ||
}, | ||
}, | ||
// This is here to prevent a cache key conflict between normal queries and | ||
// "infinite" queries. Read more here: https://tkdodo.eu/blog/effective-react-query-keys#caching-data | ||
'load-all', | ||
], | ||
...queryOptions, | ||
}); | ||
|
||
const currentNumberPages = data?.pages.length ?? 0; | ||
|
||
useEffect(() => { | ||
if (!isFetching && hasNextPage && currentNumberPages + 1 < maxPages) { | ||
fetchNextPage(); | ||
} | ||
}, [isFetching, hasNextPage, fetchNextPage, maxPages, currentNumberPages]); | ||
|
||
return { | ||
isLoading, | ||
isPending, | ||
isError, | ||
error, | ||
releases: data?.pages.flatMap(([pageData]) => pageData), | ||
}; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.