Skip to content

✨ feat: 新增列表缓存#687

Merged
kazukokawagawa merged 8 commits into
devfrom
list-cache
Dec 30, 2025
Merged

✨ feat: 新增列表缓存#687
kazukokawagawa merged 8 commits into
devfrom
list-cache

Conversation

@imsyy
Copy link
Copy Markdown
Member

@imsyy imsyy commented Dec 30, 2025

No description provided.

@gemini-code-assist
Copy link
Copy Markdown
Contributor

Summary of Changes

Hello @imsyy, 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!

此拉取请求的核心目标是引入列表数据缓存机制,以优化应用程序中歌单、专辑和电台等列表的加载性能和用户体验。通过在 CacheService 中实现 Gzip 压缩,不仅加快了数据检索速度,还降低了存储开销。此外,还包含了一些用户界面和数据处理的细节改进,以及对 Discord Rich Presence 功能的初步集成,旨在提升整体应用的响应性和稳定性。

Highlights

  • 新增列表缓存功能: 为歌单、专辑和电台数据引入了缓存机制,显著提升加载速度和用户体验。
  • 缓存服务优化: 将旧的 "playlist-data" 缓存类型统一为 "list-data",并为列表数据缓存增加了 Gzip 压缩和解压缩功能,有效减少存储空间。
  • Discord RPC 集成: 在 Electron 构建配置中加入了 "discord-rpc-for-splayer" 原生模块,为 Discord Rich Presence 功能做准备。
  • UI/UX 改进: 在列表详情页(专辑、歌单、电台)增加了“刷新缓存”选项,优化了搜索输入框的占位符更新逻辑,并修正了更新应用模态框的下载链接。
  • 数据处理健壮性增强: 多个数据格式化函数增加了 "filter(Boolean)" 处理,以避免因数据中存在 "null" 或 "undefined" 项导致的问题。
  • 本地文件夹视图修复: 解决了 "folders.vue" 中 "treeData" 在后台更新时可能导致的 DOM 渲染错误。
Using Gemini Code Assist

The 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 /gemini <command> or @gemini-code-assist <command>. Below is a summary of the supported commands on the current page.

Feature Command Description
Code Review /gemini review Performs a code review for the current pull request in its current state.
Pull Request Summary /gemini summary Provides a summary of the current pull request in its current state.
Comment @gemini-code-assist Responds in comments when explicitly tagged, both in pull request comments and review comments.
Help /gemini help Displays a list of available commands.

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 .gemini/ folder in the base of the repository. Detailed instructions can be found here.

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

  1. Review the Privacy Notices, Generative AI Prohibited Use Policy, Terms of Service, and learn how to configure Gemini Code Assist in GitHub here. Gemini can make mistakes, so double check it and use code with caution.

Copy link
Copy Markdown
Contributor

@gemini-code-assist gemini-code-assist Bot left a comment

Choose a reason for hiding this comment

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

Code Review

本次 PR 引入了对歌单、专辑和电台列表的缓存机制,这是一个很棒的功能,能够有效提升应用的性能和用户体验。整体实现非常出色,考虑到了缓存版本控制、Gzip 压缩、后台静默更新以及并发请求处理等多个方面。

代码层面,我提出了一些建议:

  1. 在新的 useListDataCache 组合式函数中,建议将用于调试的 console.log 调用替换为在生产环境中会被移除的日志方案。
  2. 在多个列表视图组件(albumplaylistradio)中,backgroundCheck 函数的 cached 参数目前是 any 类型,建议为其指定具体的 ListCacheData 类型,以增强代码的类型安全性和可维护性。

除了这些小建议,整个 PR 的代码质量很高。合并后将显著改善列表页面的加载速度。


try {
await cacheManager.set("list-data", key, jsonStr);
console.log(`✅ List cache saved: ${key}`);
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

medium

该文件中使用了大量的 console.logconsole.error 进行日志记录。虽然这在开发过程中很有用,但这些日志也会输出到生产环境的控制台,可能会造成不必要的干扰,并可能暴露应用的内部工作细节。建议使用专门的日志库,或者将这些日志包装在开发模式的条件判断中(例如 if (import.meta.env.DEV) { ... }),以避免在生产环境中输出。此建议适用于此文件中的所有 console.* 调用。

Suggested change
console.log(`✅ List cache saved: ${key}`);
if (import.meta.env.DEV) console.log(`✅ List cache saved: ${key}`);

Comment thread src/views/List/album.vue
if (currentRequestId.value !== id) return;
setDetailData(formatCoverList(detail.album)[0]);
// 获取专辑歌曲
const ids: number[] = detail.songs.map((song: any) => song.id as number);
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

medium

backgroundCheck 函数中,cached 参数的类型是 any。为了更好的类型安全和代码可读性,建议使用具体的 ListCacheData 类型。
你可以在文件顶部修改导入语句:

import { useListDataCache, type ListCacheData } from "@/composables/List/useListDataCache";

然后更新函数签名。

const backgroundCheck = async (id: number, cached: ListCacheData) => {

Comment thread src/views/List/playlist.vue Outdated
};

// 后台检查更新
const backgroundCheck = async (id: number, cached: any) => {
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

medium

album.vue 中的情况类似,backgroundCheck 函数中的 cached 参数类型为 any。建议使用 ListCacheData 类型以增强类型安全。
你可以在文件顶部修改导入语句:

import { useListDataCache, type ListCacheData } from "@/composables/List/useListDataCache";

然后更新函数签名。

const backgroundCheck = async (id: number, cached: ListCacheData) => {

Comment thread src/views/List/radio.vue Outdated
};

// 后台检查更新
const backgroundCheck = async (id: number, cached: any) => {
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

medium

album.vueplaylist.vue 中的情况类似,backgroundCheck 函数中的 cached 参数类型为 any。建议使用 ListCacheData 类型以增强类型安全。
你可以在文件顶部修改导入语句:

import { useListDataCache, type ListCacheData } from "@/composables/List/useListDataCache";

然后更新函数签名。

const backgroundCheck = async (id: number, cached: ListCacheData) => {

@imsyy imsyy marked this pull request as ready for review December 30, 2025 17:05
@imsyy
Copy link
Copy Markdown
Member Author

imsyy commented Dec 30, 2025

/gemini review

Copy link
Copy Markdown
Contributor

@gemini-code-assist gemini-code-assist Bot left a comment

Choose a reason for hiding this comment

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

Code Review

此次更新引入了列表(专辑、歌单、电台)的缓存机制,这是一个非常出色的性能和用户体验优化。整体实现考虑周全,采用了“缓存优先,网络兜底”并结合后台更新的策略,同时处理了版本控制、Gzip 压缩和并发请求等问题。代码结构清晰,改动在各个视图中保持了一致性。

我发现了一个 Bug,即在切换电台页面时,旧的歌曲列表没有被正确清除,会导致数据显示错误。此外,我还针对一处硬编码的 URL 提出了可维护性建议。

总体而言,这是一次高质量的提交。在修复提到的 Bug 后,代码便可合并。

Comment thread src/views/List/radio.vue
Comment on lines +215 to +217
if (detailData.value?.id !== id) {
setDetailData(null);
}
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

high

这里存在一个 Bug:在缓存未命中的情况下,从一个电台页面导航到另一个电台页面时,旧电台的歌曲列表(listData)没有被清空。后续调用的 getRadioAllProgram 方法会使用 appendListData 将新电台的歌曲追加到旧列表的末尾,导致显示错误的歌曲列表。

为了修复这个问题,在清除 detailData 的同时,也应该清空 listData

  if (detailData.value?.id !== id) {
    setDetailData(null);
    setListData([]);
  }

const goDownload = () => {
emit("close");
window.open(packageJson.github + "/releases", "_blank");
window.open("https://splayer.imsyy.top/download.html", "_blank");
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

medium

将下载链接硬编码到代码中会降低可维护性。如果未来下载页面的 URL 发生变化,就需要修改代码并重新发布。

建议将这个 URL 移到 package.json 文件中,就像之前的 github 链接一样。这样可以更方便地管理和更新。

例如,在 package.json 中添加:

"downloadUrl": "https://splayer.imsyy.top/download.html"

然后在代码中使用:

window.open(packageJson.downloadUrl, "_blank");

@kazukokawagawa kazukokawagawa merged commit bdad447 into dev Dec 30, 2025
4 checks passed
@kazukokawagawa kazukokawagawa deleted the list-cache branch December 30, 2025 18:09
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants