From 522bed6b7dabd09328b3c8aae90b06ab06344623 Mon Sep 17 00:00:00 2001 From: Dax Raad Date: Wed, 20 Aug 2025 16:52:43 -0400 Subject: ignore: cloud stuff --- cloud/core/src/actor.ts | 1 - cloud/core/src/drizzle/index.ts | 5 +++-- cloud/core/src/util/memo.ts | 11 +++++++++++ 3 files changed, 14 insertions(+), 3 deletions(-) create mode 100644 cloud/core/src/util/memo.ts (limited to 'cloud/core') diff --git a/cloud/core/src/actor.ts b/cloud/core/src/actor.ts index beb292bb8..0d13f7216 100644 --- a/cloud/core/src/actor.ts +++ b/cloud/core/src/actor.ts @@ -20,7 +20,6 @@ export namespace Actor { properties: { userID: string workspaceID: string - email: string } } diff --git a/cloud/core/src/drizzle/index.ts b/cloud/core/src/drizzle/index.ts index 76220f2a2..46fe93ac4 100644 --- a/cloud/core/src/drizzle/index.ts +++ b/cloud/core/src/drizzle/index.ts @@ -3,7 +3,7 @@ import { Resource } from "sst" export * from "drizzle-orm" import postgres from "postgres" -function createClient() { +const createClient = memo(() => { const client = postgres({ idle_timeout: 30000, connect_timeout: 30000, @@ -19,12 +19,13 @@ function createClient() { }) return drizzle(client, {}) -} +}) import { PgTransaction, type PgTransactionConfig } from "drizzle-orm/pg-core" import type { ExtractTablesWithRelations } from "drizzle-orm" import type { PostgresJsQueryResultHKT } from "drizzle-orm/postgres-js" import { Context } from "../context" +import { memo } from "../util/memo" export namespace Database { export type Transaction = PgTransaction< diff --git a/cloud/core/src/util/memo.ts b/cloud/core/src/util/memo.ts new file mode 100644 index 000000000..3c84cf1fb --- /dev/null +++ b/cloud/core/src/util/memo.ts @@ -0,0 +1,11 @@ +export function memo(fn: () => T) { + let value: T | undefined + let loaded = false + + return (): T => { + if (loaded) return value as T + loaded = true + value = fn() + return value as T + } +} -- cgit v1.2.3