a tool for shared writing and social publishing
0
fork

Configure Feed

Select the types of activity you want to include in your feed.

close postgres clients manually

I probably want to make a function to do this manually at some point in
the future

+19 -7
+2 -1
app/page.tsx
··· 10 10 import { Doc } from "./[doc_id]/Doc"; 11 11 import { UpdateURL } from "components/UpdateURL"; 12 12 import { v7 } from "uuid"; 13 - const client = postgres(process.env.DB_URL as string); 13 + const client = postgres(process.env.DB_URL as string, { idle_timeout: 5 }); 14 14 const db = drizzle(client); 15 15 16 16 export const preferredRegion = ["sfo1"]; ··· 49 49 return { permissionToken, rights, entity, entity_set }; 50 50 }, 51 51 ); 52 + client.end(); 52 53 // Here i need to pass the permission token instead of the doc_id 53 54 // In the replicache provider I guess I need to fetch the relevant stuff of the permission token? 54 55 return (
+9 -3
components/ShareOptions/getShareLink.ts
··· 4 4 import { drizzle } from "drizzle-orm/postgres-js"; 5 5 import { permission_token_rights, permission_tokens } from "drizzle/schema"; 6 6 import postgres from "postgres"; 7 - const client = postgres(process.env.DB_URL as string); 7 + const client = postgres(process.env.DB_URL as string, { idle_timeout: 5 }); 8 8 const db = drizzle(client); 9 9 export async function getShareLink( 10 10 token: { id: string; entity_set: string }, ··· 26 26 tokenW.permission_token_rights.create_token !== true || 27 27 tokenW.permission_tokens.root_entity !== rootEntity || 28 28 tokenW.permission_token_rights.entity_set !== token.entity_set 29 - ) 29 + ) { 30 + client.end(); 30 31 return null; 32 + } 31 33 32 34 let [existingToken] = await tx 33 35 .select() ··· 46 48 eq(permission_tokens.root_entity, rootEntity), 47 49 ), 48 50 ); 49 - if (existingToken) return existingToken.permission_tokens; 51 + if (existingToken) { 52 + client.end(); 53 + return existingToken.permission_tokens; 54 + } 50 55 let [newToken] = await tx 51 56 .insert(permission_tokens) 52 57 .values({ root_entity: rootEntity }) ··· 59 64 create_token: false, 60 65 change_entity_set: false, 61 66 }); 67 + client.end(); 62 68 return newToken; 63 69 }); 64 70 }
+2 -1
src/replicache/pull.ts
··· 17 17 process.env.SUPABASE_SERVICE_ROLE_KEY as string, 18 18 ); 19 19 20 - const client = postgres(process.env.DB_URL as string); 20 + const client = postgres(process.env.DB_URL as string, { idle_timeout: 5 }); 21 21 const db = drizzle(client); 22 22 export async function Pull( 23 23 body: PullRequest, ··· 27 27 let { data } = await supabase.rpc("get_facts", { root: rootEntity }); 28 28 let facts = data || []; 29 29 let clientGroup = await getClientGroup(db, body.clientGroupID); 30 + client.end(); 30 31 31 32 return { 32 33 cookie: Date.now(),
+6 -2
src/replicache/push.ts
··· 10 10 import { createClient } from "@supabase/supabase-js"; 11 11 import { Database } from "supabase/database.types"; 12 12 13 - const client = postgres(process.env.DB_URL as string); 13 + const client = postgres(process.env.DB_URL as string, { idle_timeout: 5 }); 14 14 let supabase = createClient<Database>( 15 15 process.env.NEXT_PUBLIC_SUPABASE_API_URL as string, 16 16 process.env.SUPABASE_SERVICE_ROLE_KEY as string, ··· 21 21 rootEntity: string, 22 22 token: { id: string }, 23 23 ): Promise<PushResponse | undefined> { 24 - if (pushRequest.pushVersion !== 1) 24 + if (pushRequest.pushVersion !== 1) { 25 + client.end(); 26 + 25 27 return { error: "VersionNotSupported", versionType: "push" }; 28 + } 26 29 let clientGroup = await getClientGroup(db, pushRequest.clientGroupID); 27 30 let token_rights = await db 28 31 .select() ··· 69 72 payload: { message: "poke" }, 70 73 }); 71 74 supabase.removeChannel(channel); 75 + client.end(); 72 76 return undefined; 73 77 }