-
Notifications
You must be signed in to change notification settings - Fork 1
⚡ [performance] optimize GCS file metadata fetching #102
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: main
Are you sure you want to change the base?
Changes from 3 commits
7605399
805ad42
d86b74f
935d3f4
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -53,16 +53,19 @@ export const proxyReportsFile = async (req, res, filePath) => { | |
| const bucket = storage.bucket(BUCKET_NAME); | ||
| const file = bucket.file(objectPath); | ||
|
|
||
| // Check if file exists | ||
| const [exists] = await file.exists(); | ||
| if (!exists) { | ||
| res.statusCode = 404; | ||
| res.end(JSON.stringify({ error: 'File not found' })); | ||
| return; | ||
| } | ||
|
|
||
| // Get file metadata for content type and caching | ||
| const [metadata] = await file.getMetadata(); | ||
| // This implicitly checks if the file exists, saving a network request | ||
| let metadata; | ||
| try { | ||
| [metadata] = await file.getMetadata(); | ||
| } catch (error) { | ||
| if (error.code === 404) { | ||
| res.statusCode = 404; | ||
| res.end(JSON.stringify({ error: 'File not found' })); | ||
| return; | ||
| } | ||
|
Comment on lines
56
to
+66
|
||
| throw error; | ||
| } | ||
|
|
||
| // Determine content type | ||
| const contentType = metadata.contentType || getMimeType(objectPath); | ||
|
|
||
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The PR description mentions adding a benchmark at
src/benchmarks/gcs_metadata.benchmark.js, but that file/directory isn’t included in this change set (and doesn’t appear to exist insrc/). Either add the benchmark file as described or update the PR description to match what’s actually being changed.