Skip to content

Commit b2ea194

Browse files
ryan953andrewshie-sentry
authored andcommitted
fix(replay): Stop refetching useProjectSdkNeedsUpdate() calls after 5s (#97656)
Previously (and previous to #97642) we were refetching any request to `useProjectSdkNeedsUpdate()` after 5 seconds. This was hurting performance, and blowing up state, on the replay list page. As a user you could see the checkbox state of the list items being reset when the new/refreshed project-sdk data arrives, even if the value is the same. Now we just fetch the data once and that's it. If people are using old SDKs and see a message, they can refresh the page to get new values, or re-mount components Fixes REPLAY-603
1 parent 8bc959b commit b2ea194

File tree

3 files changed

+21
-35
lines changed

3 files changed

+21
-35
lines changed

static/app/utils/useOrganizationSDKUpdates.tsx

Lines changed: 0 additions & 17 deletions
This file was deleted.

static/app/utils/useProjectSdkNeedsUpdate.tsx

Lines changed: 9 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,6 @@
1-
import {useOrganizationSDKUpdates} from 'sentry/utils/useOrganizationSDKUpdates';
1+
import type {ProjectSdkUpdates} from 'sentry/types/project';
2+
import {useApiQuery} from 'sentry/utils/queryClient';
3+
import useOrganization from 'sentry/utils/useOrganization';
24
import {semverCompare} from 'sentry/utils/versions/semverCompare';
35

46
type Opts = {
@@ -13,10 +15,12 @@ export default function useProjectSdkNeedsUpdate({
1315
| {isError: false; isFetching: true; needsUpdate: undefined}
1416
| {isError: true; isFetching: false; needsUpdate: undefined}
1517
| {isError: false; isFetching: false; needsUpdate: boolean} {
16-
const {data, isError, isPending} = useOrganizationSDKUpdates({
17-
projectId,
18-
enabled: true,
19-
});
18+
const organization = useOrganization();
19+
20+
const {data, isError, isPending} = useApiQuery<ProjectSdkUpdates[]>(
21+
[`/organizations/${organization.slug}/sdk-updates/`, {query: {project: projectId}}],
22+
{staleTime: Infinity, refetchOnMount: true}
23+
);
2024

2125
if (isPending) {
2226
return {isError: false, isFetching: true, needsUpdate: undefined};

static/app/views/insights/database/queries/useOutdatedSDKProjects.tsx

Lines changed: 12 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -1,25 +1,27 @@
11
import uniqBy from 'lodash/uniqBy';
22

33
import ProjectsStore from 'sentry/stores/projectsStore';
4-
import {useOrganizationSDKUpdates} from 'sentry/utils/useOrganizationSDKUpdates';
4+
import type {ProjectSdkUpdates} from 'sentry/types/project';
5+
import {useApiQuery} from 'sentry/utils/queryClient';
6+
import useOrganization from 'sentry/utils/useOrganization';
57
import {semverCompare} from 'sentry/utils/versions/semverCompare';
68
import {MIN_SDK_VERSION_BY_PLATFORM} from 'sentry/views/insights/database/settings';
79

810
interface Options {
9-
enabled?: boolean;
10-
projectId?: string[];
11+
enabled: boolean;
12+
projectId: string[];
1113
}
1214

1315
/**
1416
* Returns a list of projects that are not eligible for span metrics
1517
* due to SDK requirements.
16-
*
17-
* @param options Additional options
18-
* @param options.projectId List of project IDs to check against. If omitted, checks all organization projects
19-
* @returns List of projects
2018
*/
21-
export function useOutdatedSDKProjects(options?: Options) {
22-
const response = useOrganizationSDKUpdates(options ?? {});
19+
export function useOutdatedSDKProjects({enabled, projectId}: Options) {
20+
const organization = useOrganization();
21+
const response = useApiQuery<ProjectSdkUpdates[]>(
22+
[`/organizations/${organization.slug}/sdk-updates/`, {query: {project: projectId}}],
23+
{staleTime: 5000, enabled}
24+
);
2325
const {data: availableUpdates} = response;
2426

2527
const projects = (availableUpdates ?? [])
@@ -35,10 +37,7 @@ export function useOutdatedSDKProjects(options?: Options) {
3537

3638
return semverCompare(update.sdkVersion, minimumRequiredVersion) === -1;
3739
})
38-
.map(update => update.projectId)
39-
.map(projectId => {
40-
return ProjectsStore.getById(projectId);
41-
})
40+
.map(update => ProjectsStore.getById(update.projectId))
4241
.filter((item): item is NonNullable<typeof item> => Boolean(item));
4342

4443
return {

0 commit comments

Comments
 (0)