⚡ Bolt: Optimize config loading for plugin endpoints#104
⚡ Bolt: Optimize config loading for plugin endpoints#104Dexploarer wants to merge 1 commit intodevelopfrom
Conversation
Optimized `GET /api/plugins` and `GET /api/registry/plugins` to use the in-memory `state.config` instead of synchronously reloading the configuration file from disk on every request.
Key changes:
- `src/services/plugin-installer.ts`: `listInstalledPlugins` now accepts an optional `config` object to bypass disk read.
- `src/api/server.ts`:
- Updated `GET /api/plugins` to use `state.config`.
- Updated `GET /api/registry/plugins` to pass `state.config`.
- Added explicit config reloading in `POST /api/plugins/install` and `POST /api/plugins/uninstall` to keep `state.config` fresh after mutations.
This reduces latency for frequently accessed plugin endpoints and avoids blocking the event loop with synchronous file I/O.
|
👋 Jules, reporting for duty! I'm here to lend a hand with this pull request. When you start a review, I'll add a 👀 emoji to each comment to let you know I've read it. I'll focus on feedback directed at me and will do my best to stay out of conversations between you and other bots or reviewers to keep the noise down. I'll push a commit with your requested changes shortly after. Please note there might be a delay between these steps, but rest assured I'm on the job! For more direct control, you can switch me to Reactive Mode. When this mode is on, I will only act on comments where you specifically mention me with New to Jules? Learn more at jules.google/docs. For security, I will only act on instructions from the user who triggered this task. |
|
Important Review skippedDraft detected. Please check the settings in the CodeRabbit UI or the You can disable this status message by setting the Use the checkbox below for a quick retry:
✨ Finishing Touches🧪 Generate unit tests (beta)
Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out. Comment |
Summary of ChangesHello @Dexploarer, I'm Gemini Code Assist1! I'm currently reviewing this pull request and will post my feedback shortly. In the meantime, here's a summary to help you and other reviewers quickly get up to speed! This pull request significantly improves the performance and responsiveness of plugin-related API endpoints by refactoring how configuration data is accessed. It transitions from a synchronous, disk-based config loading mechanism on every request to leveraging an in-memory cache, thereby removing a blocking I/O operation from critical paths. The change ensures that the in-memory configuration is consistently updated following any modifications, such as plugin installations or uninstallations. Highlights
🧠 New Feature in Public Preview: You can now enable Memory to help Gemini Code Assist learn from your team's feedback. This makes future code reviews more consistent and personalized to your project's style. Click here to enable Memory in your admin console. Changelog
Activity
Using Gemini Code AssistThe full guide for Gemini Code Assist can be found on our documentation page, here are some quick tips. Invoking Gemini You can request assistance from Gemini at any point by creating a comment using either
Customization To customize Gemini Code Assist for GitHub experience, repository maintainers can create a configuration file and/or provide a custom code review style guide (such as PEP-8 for Python) by creating and adding files to a Limitations & Feedback Gemini Code Assist may make mistakes. Please leave feedback on any instances where its feedback is incorrect or counter productive. You can react with 👍 and 👎 on @gemini-code-assist comments. If you're interested in giving your feedback about your experience with Gemini Code Assist for Github and other Google products, sign up here. You can also get AI-powered code generation, chat, as well as code reviews directly in the IDE at no cost with the Gemini Code Assist IDE Extension. Footnotes
|
| const cfg = config ?? loadMilaidyConfig(); | ||
| const installs = cfg.plugins?.installs ?? {}; | ||
|
|
There was a problem hiding this comment.
The function does not handle errors that may occur if loadMilaidyConfig() fails (e.g., due to a malformed or missing config file). This could result in an unhandled exception and crash the process.
Recommendation: Wrap the config loading and access in a try-catch block and return an empty array or a meaningful error if the config cannot be loaded safely.
| const installs = cfg.plugins?.installs ?? {}; | ||
|
|
There was a problem hiding this comment.
There is a potential for inconsistent reads if the config is being modified concurrently by another operation (such as install or uninstall). This could result in a partial or outdated list of plugins being returned.
Recommendation: Consider implementing a read/write lock or other synchronization mechanism to ensure that config reads and writes are atomic and consistent.
There was a problem hiding this comment.
Code Review
This pull request optimizes configuration loading for plugin-related endpoints by removing synchronous file reads and leveraging an in-memory configuration cache. The configuration is now explicitly reloaded only after modification, such as during plugin installation or uninstallation. The changes are logical and effectively address the performance concern of blocking I/O on hot API paths. I've identified a minor code duplication for the configuration reloading logic, which could be refactored to improve maintainability.
| // Reload config to sync state | ||
| try { | ||
| state.config = loadMilaidyConfig(); | ||
| } catch (err) { | ||
| logger.warn( | ||
| `[milaidy-api] Failed to reload config after install: ${err}`, | ||
| ); | ||
| } |
There was a problem hiding this comment.
This logic to reload the configuration is duplicated in the uninstall handler as well (lines 3232-3239). To improve maintainability and reduce code duplication, consider extracting this into a helper function.
For example, you could define a function like this at the module level:
function reloadConfigState(state: ServerState, action: 'install' | 'uninstall'): void {
try {
state.config = loadMilaidyConfig();
} catch (err) {
logger.warn(
`[milaidy-api] Failed to reload config after ${action}: ${err instanceof Error ? err.message : String(err)}`,
);
}
}Then you could call reloadConfigState(state, 'install') here and reloadConfigState(state, 'uninstall') in the other handler. This also makes the error logging safer.
| // Reload config to sync state | ||
| try { | ||
| state.config = loadMilaidyConfig(); | ||
| } catch (err) { | ||
| logger.warn( | ||
| `[milaidy-api] Failed to reload config after uninstall: ${err}`, | ||
| ); | ||
| } |
⚡ Bolt: Optimize config loading for plugin endpoints
💡 What:
Removed synchronous
loadMilaidyConfig()calls fromGET /api/pluginsandGET /api/registry/pluginsby leveraging the existing in-memorystate.config. Explicitly reloads configuration only when it is modified via install/uninstall endpoints.🎯 Why:
The previous implementation re-read the configuration file from disk on every request to
/api/plugins, which blocked the event loop due to synchronous I/O. This was unnecessary as the server maintains the configuration state in memory.📊 Impact:
Reduces I/O overhead and latency for plugin listing endpoints. Eliminates a synchronous blocking operation from the hot path of the API.
🔬 Measurement:
Verified with a reproduction test (
src/api/repro_issue.test.ts) which confirmed thatloadMilaidyConfigis no longer called onGET /api/pluginsrequests, whereas it was called previously.PR created automatically by Jules for task 8380716501792575775 started by @Dexploarer