feat(setting): 支持自定义缓存大小上限,更改 cacheLimit 单位为字节#642
feat(setting): 支持自定义缓存大小上限,更改 cacheLimit 单位为字节#642
Conversation
Summary of ChangesHello @MoYingJi, 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! 此拉取请求主要改进了应用程序的缓存大小限制功能。通过将内部缓存限制单位统一为字节,并为用户提供更灵活的自定义设置选项(包括数值输入和单位选择),极大地增强了用户体验和系统稳定性。此外,还引入了2GB的最小缓存限制,以防止意外设置过小的缓存导致问题。 Highlights
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
|
| amllDbServer: defaultAMLLDbServer, | ||
| cachePath: join(app.getPath("userData"), "DataCache"), | ||
| cacheLimit: 10, // 默认 10GB | ||
| cacheLimit: 10 * (1024 ** 3), // 默认 10GB |
There was a problem hiding this comment.
此更改将 cacheLimit 的单位从 GB 更改为字节,但缺少对现有用户配置的数据迁移逻辑。对于现有用户,其 electron-store 中存储的 cacheLimit 值(例如 10 代表 10GB)将被错误地解释为字节(10 字节),这会破坏缓存功能。需要在应用启动时添加一次性迁移逻辑,将旧的 GB 值转换为字节。
建议在 useStore 函数中,初始化 Store 实例后添加如下迁移代码:
const store = new Store<StoreType>(...);
const cacheLimit = store.get('cacheLimit');
// 假设旧的 GB 值是小于 1000 的小整数
if (cacheLimit > 0 && cacheLimit < 1000) {
store.set('cacheLimit', cacheLimit * (1024 ** 3));
}
return store;There was a problem hiding this comment.
仍在开发中,加入此功能到此 PR 期间没有发布 Release
| // 恢复数值 | ||
| await updateCacheLimit(); |
There was a problem hiding this comment.
在 onMounted 钩子中,通过调用 updateCacheLimit() 来恢复缓存限制的数值,这是不正确的。updateCacheLimit 会将 Pinia store (UI state) 中的值写入 electron-store,这会导致覆盖用户在 electron-store 中已有的设置。正确的逻辑应该是从 electron-store 读取值,然后更新 Pinia store 来初始化 UI。
// 恢复数值
const limitInBytes = await window.api.store.get("cacheLimit");
if (typeof limitInBytes === "number") {
if (limitInBytes === 0) {
settingStore.cacheLimitMultiplier = 0;
settingStore.cacheLimitValue = 10; // 或其他合适的默认值
} else if (limitInBytes >= 1024 ** 3 && limitInBytes % (1024 ** 3) === 0) {
settingStore.cacheLimitMultiplier = 1024 ** 3; // GB
settingStore.cacheLimitValue = limitInBytes / (1024 ** 3);
} else {
settingStore.cacheLimitMultiplier = 1024 ** 2; // MB
settingStore.cacheLimitValue = Math.round(limitInBytes / (1024 ** 2));
}
}
// 确保数值符合最小限制
await updateCacheLimit();
There was a problem hiding this comment.
但这样就丢失掉了单位的信息诶
比如我设置了 10240 MB 的大小,下次打开就自动变成 10 GB 了,单位信息丢掉了
| await this.cacheService.cleanOldCache( | ||
| "music", | ||
| currentSize - limitSizeBytes + 100 * 1024 * 1024, | ||
| currentSize - limitSizeBytes + (100 * 1024 * 1024), |
There was a problem hiding this comment.
There was a problem hiding this comment.
我啥也没改啊 我就加了个括号而已哈基米大人放过我吧
24f8efb to
9f1a4c4
Compare
|
@MoYingJi |
|
那感觉就和原来没啥区别了哇 在这基础上改还不如重新水了.jpg( |
No description provided.