UBERF-8884 Use direct connection to database (#7426)

Signed-off-by: Alexander Onnikov <Alexander.Onnikov@xored.com>
This commit is contained in:
Alexander Onnikov 2024-12-11 19:42:39 +07:00 committed by GitHub
parent e39094b3fe
commit 224d003d64
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
3 changed files with 16 additions and 7 deletions

View File

@ -44,10 +44,14 @@ export async function handleBlobGet (
const { workspace, name } = request const { workspace, name } = request
const cache = new LoggedCache(caches.default, metrics) const cache = new LoggedCache(caches.default, metrics)
const cacheControl = request.headers.get('Cache-Control') ?? ''
if (!cacheControl.includes('no-cache')) {
const cached = await cache.match(request) const cached = await cache.match(request)
if (cached !== undefined) { if (cached !== undefined) {
return cached return cached
} }
}
const { bucket } = selectStorage(env, workspace) const { bucket } = selectStorage(env, workspace)
@ -75,9 +79,11 @@ export async function handleBlobGet (
const response = new Response(object?.body, { headers, status }) const response = new Response(object?.body, { headers, status })
if (response.status === 200) { if (response.status === 200) {
if (!cacheControl.includes('no-store')) {
const clone = metrics.withSync('response.clone', () => response.clone()) const clone = metrics.withSync('response.clone', () => response.clone())
ctx.waitUntil(cache.put(request, clone)) ctx.waitUntil(cache.put(request, clone))
} }
}
return response return response
} }

View File

@ -50,12 +50,14 @@ export async function withPostgres<T> (
fn: (db: BlobDB) => Promise<T> fn: (db: BlobDB) => Promise<T>
): Promise<T> { ): Promise<T> {
const sql = metrics.withSync('db.connect', () => { const sql = metrics.withSync('db.connect', () => {
return postgres(env.HYPERDRIVE.connectionString, { return postgres(env.DB_URL, {
connection: { connection: {
application_name: 'datalake' application_name: 'datalake'
} },
fetch_types: false
}) })
}) })
const db = new LoggedDB(new PostgresDB(sql), metrics) const db = new LoggedDB(new PostgresDB(sql), metrics)
try { try {

View File

@ -12,6 +12,7 @@ interface Env {
STREAMS_ACCOUNT_ID: string; STREAMS_ACCOUNT_ID: string;
STREAMS_AUTH_KEY: string; STREAMS_AUTH_KEY: string;
R2_ACCOUNT_ID: string; R2_ACCOUNT_ID: string;
DB_URL: string;
DATALAKE_APAC_ACCESS_KEY: string; DATALAKE_APAC_ACCESS_KEY: string;
DATALAKE_APAC_SECRET_KEY: string; DATALAKE_APAC_SECRET_KEY: string;
DATALAKE_APAC_BUCKET_NAME: string; DATALAKE_APAC_BUCKET_NAME: string;