Skip to content
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 3 additions & 0 deletions .jules/bolt.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
## 2024-05-23 - [File Read Opt]
**Learning:** Prefer `await fs.promises.readFile` over `fs.readFileSync` for reading files inside async functions, to avoid blocking the event loop and improve server performance.
**Action:** Replace `fs.readFileSync` with `await fs.promises.readFile` in `src/init-server.ts`.
3 changes: 2 additions & 1 deletion src/init-server.ts
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,8 @@ async function loadOpenApiSpec(specPath: string, baseUrl: string | undefined): P
let rawSpec: string

try {
rawSpec = fs.readFileSync(path.resolve(process.cwd(), specPath), 'utf-8')
// ⚑ Bolt Optimization: Use async readFile instead of readFileSync to avoid blocking the event loop during initialization
rawSpec = await fs.promises.readFile(path.resolve(process.cwd(), specPath), 'utf-8')
Comment on lines +20 to +21

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

medium

The comment added on line 20 is redundant and contains branding ('⚑ Bolt Optimization') which is unnecessary in the source code. The code itself is self-explanatory as it clearly indicates an asynchronous file read operation. Removing this comment will keep the codebase cleaner and more maintainable.

Suggested change
// ⚑ Bolt Optimization: Use async readFile instead of readFileSync to avoid blocking the event loop during initialization
rawSpec = await fs.promises.readFile(path.resolve(process.cwd(), specPath), 'utf-8')
rawSpec = await fs.promises.readFile(path.resolve(process.cwd(), specPath), 'utf-8')

} catch (error) {
console.error('Failed to read OpenAPI specification file:', (error as Error).message)
process.exit(1)
Expand Down