refactor(music-cache): 模糊匹配时按音质优先级自动选择最佳缓存#1009
Conversation
- 添加音质优先级映射表,支持多种音质等级排序 - 实现缓存元数据文件管理,存储MD5和文件大小信息 - 新增getMetaPath、readMeta、writeMeta等元数据操作方法 - 实现pickCandidates方法按音质优先级和修改时间选择候选缓存 - 重构hasCache方法支持按音质优先级自动选择最佳缓存 - 改进MD5验证逻辑,添加元数据缓存减少重复计算 - 优化下载完成后的元数据写入流程
Summary of ChangesHello, 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! 此拉取请求旨在全面提升音乐缓存服务的智能性和可靠性。通过引入音质优先级管理和独立的缓存元数据文件,系统现在能够更精确地管理和选择缓存的音乐文件,确保用户始终获得最佳音质体验。同时,MD5验证机制得到了显著增强,利用元数据缓存避免了重复计算,从而提高了缓存验证的效率和准确性。 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. Footnotes
|
|
你是不是切错分支了( |
|
应该不影响合并(( 不小心把env传上来了 现在回学校了要等下周再改
原始邮件
发件人:MoYingJi ***@***.***>
发件时间:2026年3月22日 07:28
收件人:imsyy/SPlayer ***@***.***>
抄送:LaoShui ***@***.***>, Author ***@***.***>
主题:Re: [imsyy/SPlayer] feat(electron): 优化音乐缓存服务的音质优先级和MD5验证机制 (PR #1009)
MoYingJi left a comment (SPlayer-Dev/SPlayer#1009)
你是不是切错分支了(
—
Reply to this email directly, view it on GitHub, or unsubscribe.
You are receiving this because you authored the thread.
|
- 添加了精确缓存检查和获取候选缓存的错误捕获及警告日志 - 将元数据写入改为异步执行避免阻塞主流程 - 添加了元数据写入失败的错误处理和警告日志 - 保持了文件重命名和缓存大小记录功能的正常执行
Co-authored-by: MoYingJi <moyingjiaw@outlook.com>
MoYingJi
left a comment
There was a problem hiding this comment.
我不太认同使用 .meta.json 文件存储元数据
我觉得校验哈希并不占太多时间,基本可以忽略不计
# 大小最大的文件
> du -h ./* | sort --numeric-sort | tail -1
92M ./2630874953_Hi-Res.sc
# 测量时间
> time md5sum 2630874953_Hi-Res.sc
cd7fb8a62ee113b20dc6d6d0d955684a 2630874953_Hi-Res.sc
real 0m0.100s
user 0m0.089s
sys 0m0.011s
即使你认为计算 md5sum 的时间会拖慢缓存检索速度,也可以使用项目已有的数据库存储这些信息,而不是新建一个文件(我相信当时把歌词缓存从 json 文件换成数据库也是有理由的)。现在直接新建了一个 .meta.json 文件,还是和 .sc 混在一起放
- 移除文件系统元数据文件读写,改用缓存服务存储 - 删除不再使用的 getMetaPath 方法 - 更新 readMeta 方法以从缓存中读取元数据 - 修改 writeMeta 方法将元数据写入缓存服务 - 调整 removeCacheWithMeta 方法使用缓存服务删除元数据 - 简化元数据键名生成逻辑
|
@gemini-code-assist review |
There was a problem hiding this comment.
Code Review
This pull request enhances the MusicCacheService by implementing a quality priority system and a more robust cache selection mechanism. When checking for a cache, the service now sorts candidates by audio quality and modification time. The review feedback suggests normalizing quality strings to be case-insensitive, implementing the missing metadata management for MD5 calculation mentioned in the PR description, and optimizing the file listing process to prevent performance degradation.
| return filePath; | ||
| } | ||
| try { | ||
| const fileMD5 = await this.calculateMD5(filePath); |
| private async pickCandidates( | ||
| id: number | string, | ||
| ): Promise<Array<{ filePath: string; quality: string }>> { | ||
| const items = await this.cacheService.list("music"); |
- 将音质优先级映射中的键值从大写改为小写 - 修改getQualityWeight方法以支持大小写不敏感的音质匹配 - 确保音质比较时统一转换为小写进行匹配
- 删除了 private removeCacheFile 方法 - 将文件删除逻辑直接内联到调用处 - 保持相同的错误处理行为
|
把标题和内容改了下,更符合当前 PR 的更改 |
- 移除注释中的枚举值兼容性说明 - 统一音质键名的字符串格式 - 删除冗余的音质选项如lossless、flac、exhigh等 - 保留核心音质等级配置 - 优化对象结构提高可读性
| /** 音质优先级 */ | ||
| private readonly qualityPriority: Record<string, number> = { | ||
| "master": 100, | ||
| "dolby": 95, | ||
| "spatial": 90, | ||
| "surround": 85, | ||
| "hi-res": 80, | ||
| "sq": 70, | ||
| "hq": 60, | ||
| "mq": 50, | ||
| "lq": 40, | ||
| "standard": 40, | ||
| }; |
There was a problem hiding this comment.
我在思考 master、dolby、spatial、surround 这四个 AI 音质是否要给到更高的优先级,尤其是 dolby(杜比全景声)和 surround(沉浸环绕声)和其它的普通音质都不在一组内了
Uh oh!
There was an error while loading. Please reload this page.