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

View File

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

View File

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