The Postgres development platform. Supabase gives you a dedicated Postgres database to build your web, mobile, and AI applications.
TypeScript aialternativeauthdatabasedenoembeddingsexamplefirebasenextjsoauth2pgvectorpostgispostgrespostgresqlpostgrestrealtimesupabasevectorswebsockets
fix: re-enable ConnectingState
phamhieu4e1c370ce262
diff --git a/studio/components/layouts/ProjectLayout/ConnectingState.tsx b/studio/components/layouts/ProjectLayout/ConnectingState.tsxindex ece09ceb9ee..fdef9148409 100644--- a/studio/components/layouts/ProjectLayout/ConnectingState.tsx+++ b/studio/components/layouts/ProjectLayout/ConnectingState.tsx@@ -4,9 +4,9 @@ import { observer } from 'mobx-react-lite'import { Badge, IconLoader, IconMonitor, IconServer } from '@supabase/ui'import { Project } from 'types'-import { headWithTimeout } from 'lib/common/fetch'import { useStore } from 'hooks'import ShimmerLine from 'components/ui/ShimmerLine'+import pingPostgrest from 'lib/pingPostgrest'interface Props {project: Project@@ -19,24 +19,19 @@ const ProjectRestartingState: FC<Props> = ({ project }) => {useEffect(() => {if (!project.restUrl || !project.internalApiKey) return- // Check project connection status every 4 seconds- checkProjectConnectionIntervalRef.current = window.setInterval(testProjectConnection, 4000)+ // Check project connection status every 7 seconds+ // pingPostgrest timeouts in 5s, wait for another 2s before checking again+ checkProjectConnectionIntervalRef.current = window.setInterval(testProjectConnection, 7000)return () => {clearInterval(checkProjectConnectionIntervalRef.current)}}, [project])const testProjectConnection = async () => {- const headers = {- apikey: project.internalApiKey,- Authorization: `Bearer ${project.internalApiKey}`,- }- const { error } = await headWithTimeout(project.restUrl!, [], {- headers,- credentials: 'omit',- timeout: 2000,+ const result = await pingPostgrest(project.restUrl!, project.internalApiKey!, {+ kpsVersion: project.kpsVersion,})- if (error === undefined) {+ if (result) {clearInterval(checkProjectConnectionIntervalRef.current)app.onProjectPostgrestStatusUpdated(project.id, 'ONLINE')}diff --git a/studio/components/layouts/ProjectLayout/ProjectLayout.tsx b/studio/components/layouts/ProjectLayout/ProjectLayout.tsxindex 7fb584e514d..1eba9da18cb 100644--- a/studio/components/layouts/ProjectLayout/ProjectLayout.tsx+++ b/studio/components/layouts/ProjectLayout/ProjectLayout.tsx@@ -103,12 +103,9 @@ const ContentWrapper: FC<ContentWrapperProps> = observer(({ isLoading, children<>{isLoading || ui.selectedProject === undefined ? (<Connecting />- ) : // [TODO] Temp fix commenting out ConnectingState as some projects take- // really long to ping postgrest such that the timeout cancels out too early- // requiresDbConnection && isProjectOffline ? (- // <ConnectingState project={ui.selectedProject} />- // ) :- requiresDbConnection && isProjectBuilding ? (+ ) : requiresDbConnection && isProjectOffline ? (+ <ConnectingState project={ui.selectedProject} />+ ) : requiresDbConnection && isProjectBuilding ? (<BuildingState project={ui.selectedProject} />) : (<>{children}</>diff --git a/studio/lib/pingPostgrest.ts b/studio/lib/pingPostgrest.tsindex 883fdc018a9..282d8a8f393 100644--- a/studio/lib/pingPostgrest.ts+++ b/studio/lib/pingPostgrest.ts@@ -2,7 +2,7 @@ import semver from 'semver'import { headWithTimeout, getWithTimeout } from './common/fetch'/**- * Ping Postgrest for health check+ * Ping Postgrest for health check. Default timeout in 5s.** Project with version gte 'kps-v3.8.6', we can ping the health-check api* else ping the OpenApi url@@ -37,7 +37,7 @@ async function pingPostgrest(export default pingPostgrest/**- * Send a HEAD request to postgrest OpenAPI. Default timeout in 5s+ * Send a HEAD request to postgrest OpenAPI.** @return true if there's no error else false*/@@ -52,7 +52,7 @@ async function pingOpenApi(url: string, apikey: string, timeout?: number) {}/**- * Send a GET request to postgrest health check api. Default timeout in 5s+ * Send a GET request to postgrest health check api.** @return true if there's no error else false*/diff --git a/studio/stores/app/ProjectStore.ts b/studio/stores/app/ProjectStore.tsindex 5d646c65097..0d304a59366 100644--- a/studio/stores/app/ProjectStore.ts+++ b/studio/stores/app/ProjectStore.ts@@ -1,9 +1,11 @@import { Project } from 'types'import { IRootStore } from '../RootStore'import { constructHeaders } from 'lib/api/apiHelpers'-import { get, headWithTimeout } from 'lib/common/fetch'-import PostgresMetaInterface, { IPostgresMetaInterface } from '../common/PostgresMetaInterface'+import { get } from 'lib/common/fetch'import { PROJECT_STATUS } from 'lib/constants'+import PostgresMetaInterface, { IPostgresMetaInterface } from '../common/PostgresMetaInterface'++import pingPostgrest from 'lib/pingPostgrest'export interface IProjectStore extends IPostgresMetaInterface<Project> {fetchDetail: (projectRef: string) => void@@ -27,31 +29,19 @@ export default class ProjectStore extends PostgresMetaInterface<Project> {const response = await get(url, { headers })if (!response.error) {const project = response as Project- // [TODO] Tempfix comment out ConnectingState- // if (- // project.status === PROJECT_STATUS.ACTIVE_HEALTHY &&- // project.restUrl &&- // project.internalApiKey- // ) {- // const success = await this.pingPostgrest(project.restUrl, project.internalApiKey)- // project.postgrestStatus = success ? 'ONLINE' : 'OFFLINE'- // }+ if (+ project.status === PROJECT_STATUS.ACTIVE_HEALTHY &&+ project.restUrl &&+ project.internalApiKey+ ) {+ const success = await pingPostgrest(project.restUrl, project.internalApiKey, {+ kpsVersion: project.kpsVersion,+ // only wait for 2s. to improve project first load+ timeout: 2000,+ })+ project.postgrestStatus = success ? 'ONLINE' : 'OFFLINE'+ }this.data[project.id] = project}}-- /**- * Send a HEAD request to postgrest OpenAPI- *- * @return true if there's no error else false- */- async pingPostgrest(restUrl: string, apikey: string) {- const headers = { apikey, Authorization: `Bearer ${apikey}` }- const { error } = await headWithTimeout(restUrl, [], {- headers,- credentials: 'omit',- timeout: 2000,- })- return error === undefined- }}