Skip to content

The Postgres development platform. Supabase gives you a dedicated Postgres database to build your web, mobile, and AI applications.

Chore/tiny refactor org limit (#51550)

Joshen Limfe8b4df66d59
diff --git a/apps/studio/components/interfaces/Account/AccessTokens/Scoped/Form/ResourceAccessStep.tsx b/apps/studio/components/interfaces/Account/AccessTokens/Scoped/Form/ResourceAccessStep.tsx
index e8678654068..05cad762ff3 100644
--- a/apps/studio/components/interfaces/Account/AccessTokens/Scoped/Form/ResourceAccessStep.tsx
+++ b/apps/studio/components/interfaces/Account/AccessTokens/Scoped/Form/ResourceAccessStep.tsx
@@ -78,10 +78,7 @@ export const ResourceAccessStep = ({
data: projectsData,
hasNextPage,
fetchNextPage,
- } = useOrgProjectsInfiniteQuery({
- slug: selectedOrgSlug,
- limit: 100,
- })
+ } = useOrgProjectsInfiniteQuery({ slug: selectedOrgSlug })
const projectsForOrg = useMemo(
() => projectsData?.pages.flatMap((page) => page.projects) ?? [],
diff --git a/apps/studio/components/interfaces/Organization/GeneralSettings/DeleteOrganizationButton.tsx b/apps/studio/components/interfaces/Organization/GeneralSettings/DeleteOrganizationButton.tsx
index 74baf2ba06e..193d8df34c8 100644
--- a/apps/studio/components/interfaces/Organization/GeneralSettings/DeleteOrganizationButton.tsx
+++ b/apps/studio/components/interfaces/Organization/GeneralSettings/DeleteOrganizationButton.tsx
@@ -36,10 +36,7 @@ export const DeleteOrganizationButton = () => {
isFetching,
isError,
} = useOrgProjectsInfiniteQuery(
- {
- slug: orgSlug,
- limit: MAX_PROJECT_ACKNOWLEDGEMENTS + 1,
- },
+ { slug: orgSlug },
{
enabled: isOpen,
refetchOnMount: 'always',
diff --git a/apps/studio/components/layouts/Navigation/NavigationBar/OrgSelector.tsx b/apps/studio/components/layouts/Navigation/NavigationBar/OrgSelector.tsx
index dbff9bf38ed..297666376f7 100644
--- a/apps/studio/components/layouts/Navigation/NavigationBar/OrgSelector.tsx
+++ b/apps/studio/components/layouts/Navigation/NavigationBar/OrgSelector.tsx
@@ -40,7 +40,7 @@ export function OrgSelector() {
const isPlatformOrg = selectedOrganization?.plan?.id === 'platform'
const selectedOrgInitial = selectedOrganization?.name?.trim().charAt(0).toUpperCase() || 'O'
const { data: projects } = useOrgProjectsInfiniteQuery(
- { slug, limit: 1 },
+ { slug },
{ enabled: Boolean(slug) && !isPlatformOrg }
)
diff --git a/apps/studio/data/projects/keys.ts b/apps/studio/data/projects/keys.ts
index 10da61d84b1..6160ec315e1 100644
--- a/apps/studio/data/projects/keys.ts
+++ b/apps/studio/data/projects/keys.ts
@@ -9,7 +9,6 @@ export const projectKeys = {
infiniteListByOrg: (
slug: string | undefined,
params?: {
- limit: number
sort?: 'name_asc' | 'name_desc' | 'created_asc' | 'created_desc'
search?: string
statuses?: string[]
diff --git a/apps/studio/data/projects/org-projects-infinite-query.ts b/apps/studio/data/projects/org-projects-infinite-query.ts
index 4e15316638b..a8bfc11e68f 100644
--- a/apps/studio/data/projects/org-projects-infinite-query.ts
+++ b/apps/studio/data/projects/org-projects-infinite-query.ts
@@ -7,14 +7,20 @@ import { get, handleError } from '@/data/fetchers'
import { useProfile } from '@/lib/profile'
import type { ResponseError, UseCustomInfiniteQueryOptions } from '@/types'
-// [Joshen] Try to keep this value a multiple of 6 (common denominator of 2 and 3) to fit the cards view
-// So that the last row will always be a full row of cards while there's a next page
-// API max rows is 100, I'm just choosing 96 here as the highest value thats a multiple of 6
+/**
+ * [Joshen] Try to keep this value a multiple of 6 (common denominator of 2 and 3) to fit the cards
+ * view on the project home page, So that the last row will always be a full row of cards while
+ * there's a next page. API max rows is 100, I'm just choosing 96 here as the highest value thats a
+ * multiple of 6.
+ *
+ * Also deliberately omitting limit as a param in this RQ hook just so we can consistently use the same
+ * cached data and not unnecessarily ping API for different limit values. (Let me know if there happens
+ * to be a UI that might need a specific limit value that we need to reintroduce that param)
+ */
const DEFAULT_LIMIT = 96
interface GetOrgProjectsInfiniteVariables {
slug?: string
- limit?: number
sort?: 'name_asc' | 'name_desc' | 'created_asc' | 'created_desc'
search?: string
page?: number
@@ -27,7 +33,6 @@ export type OrgProject = OrgProjectsResponse['projects'][number]
export async function getOrganizationProjects(
{
slug,
- limit = DEFAULT_LIMIT,
page = 0,
sort = 'name_asc',
search: _search = '',
@@ -38,6 +43,7 @@ export async function getOrganizationProjects(
) {
if (!slug) throw new Error('Slug is required')
+ const limit = DEFAULT_LIMIT
const offset = page * limit
const search = _search.length === 0 ? undefined : _search
const statuses = _statuses.length === 0 ? undefined : _statuses.join(',')
@@ -56,13 +62,7 @@ export type OrgProjectsInfiniteData = Awaited<ReturnType<typeof getOrganizationP
export type OrgProjectsInfiniteError = ResponseError
export const useOrgProjectsInfiniteQuery = <TData = OrgProjectsInfiniteData>(
- {
- slug,
- limit = DEFAULT_LIMIT,
- sort = 'name_asc',
- search,
- statuses = [],
- }: GetOrgProjectsInfiniteVariables,
+ { slug, sort = 'name_asc', search, statuses = [] }: GetOrgProjectsInfiniteVariables,
{
enabled = true,
...options
@@ -76,15 +76,15 @@ export const useOrgProjectsInfiniteQuery = <TData = OrgProjectsInfiniteData>(
) => {
const { profile } = useProfile()
return useInfiniteQuery({
- queryKey: projectKeys.infiniteListByOrg(slug, { limit, sort, search, statuses }),
+ queryKey: projectKeys.infiniteListByOrg(slug, { sort, search, statuses }),
queryFn: ({ signal, pageParam }) =>
- getOrganizationProjects({ slug, limit, page: pageParam, sort, search, statuses }, signal),
+ getOrganizationProjects({ slug, page: pageParam, sort, search, statuses }, signal),
enabled: enabled && profile !== undefined && typeof slug !== 'undefined',
staleTime: 30 * 60 * 1000, // 30 minutes
initialPageParam: 0,
getNextPageParam(lastPage, pages) {
const page = pages.length
- const currentTotalCount = page * limit
+ const currentTotalCount = page * DEFAULT_LIMIT
const totalCount = lastPage.pagination?.count
if (totalCount === undefined || currentTotalCount >= totalCount) return undefined
diff --git a/apps/studio/hooks/misc/useUserProjectRegions.ts b/apps/studio/hooks/misc/useUserProjectRegions.ts
index 680f7e0660e..0580ecbe786 100644
--- a/apps/studio/hooks/misc/useUserProjectRegions.ts
+++ b/apps/studio/hooks/misc/useUserProjectRegions.ts
@@ -8,7 +8,6 @@ import {
} from '@/data/projects/org-projects-infinite-query'
import { normalizeRegion, type UserRegionContext } from '@/lib/status-page/status-page.utils'
-const PROJECTS_PAGE_LIMIT = 100
const PROJECTS_STALE_TIME_MS = 5 * 60 * 1000
const LOADING: UserProjectRegionsState = { status: 'loading' }
@@ -54,7 +53,7 @@ export function useUserProjectRegions({ enabled }: { enabled: boolean }): UserPr
queries: (organizations ?? []).map((org) => ({
queryKey: projectKeys.bannerProjectsByOrg(org.slug),
queryFn: ({ signal }: { signal: AbortSignal }) =>
- getOrganizationProjects({ slug: org.slug, limit: PROJECTS_PAGE_LIMIT }, signal),
+ getOrganizationProjects({ slug: org.slug }, signal),
staleTime: PROJECTS_STALE_TIME_MS,
enabled,
})),