Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

v7.3.1 #895

Merged
merged 29 commits into from
Jan 13, 2025
Merged

v7.3.1 #895

merged 29 commits into from
Jan 13, 2025

Conversation

Ghost-chu
Copy link
Collaborator

@Ghost-chu Ghost-chu commented Jan 12, 2025

v7.3.1 是 v7.3.0 的一个补丁,有关 v7.3.0 的主要更新内容,请参见 v7.3.0 更新日志

错误修复

  • 修复暂停下载器的状态无法被保存的问题 @Ghost-chu
  • 修复 qBittorrent 下载器登陆状态/有效性检查不正确的问题 @Ghost-chu
  • 修复当下载器被暂停或者由于种种原因处于非活跃(登录失败等)状态时出现 Cannot invoke "java.util.Map.keySet()" because "provided" is null 异常的问题 @Ghost-chu
  • [WebUI] 修复更新日志宽度 @Gaojianli
  • [WebUI] 修复图表透明度问题 @Gaojianli

优化

  • 优化整体平均 CPU 使用率 @Ghost-chu
  • 使用内存映射文件(mmap)技术改善 GeoIP 读取性能,并充分利用操作系统内存文件缓存 @Ghost-chu
  • 使用内存映射文件(mmap)技术改善 SQLite 查询性能 @Ghost-chu
  • 在长时间运行 PeerBanHelper 时,定期执行 SQLite 优化查询 @Ghost-chu
  • 改进 ARB 和其它查询 BAN_LIST 列表的封禁模块的读性能 @Ghost-chu

已知问题

  • 暗色模式下,更新日志可能存在显示异常
    • 切换到日间模式查看可缓解此问题
  • 在更新或重启 PeerBanHelper 时没有在浏览器中关闭已经打开的 WebUI 标签页时,可能引发多次失败请求,以致触发防暴力破解保护,封禁用户 IP
    • 如果出现这种情况,请关闭所有 PeerBanHelper WebUI 标签页后,重新启动 PeerBanHelper 来解除对 IP 的封禁
    • 如果无法重新启动以解除 IP 封禁,则可以关闭所有 WebUI 标签页后,等待 30 分钟后再试(期间如有任何失败请求,都将重置计时器)

版本升级指南

由于经常有用户询问如何升级,我们在此列出几种主要安装方式的升级步骤以供参考:

使用 Windows、macOS、Linux(.sh) 安装程序 (install4j) 的用户

启动 PeerBanHelper 时将自动检查更新,并在更新可用时自动升级。
您也可以运行 "PeerBanHelper 检查更新" 程序,手动检查更新并升级。

手动升级的用户,请下载安装程序,并在安装向导中选择 “是,升级现有的安装”

使用群晖套件的用户

请等待矿神 SPK 源更新后在套件中心中升级。

使用 Docker-compose 的用户

更改镜像标签后重新部署即可。

使用 docker 命令的用户

请做好容器数据备份,删除旧的容器,并使用新的镜像标签重新运行 docker run 命令进行升级。建议配合 watchtower 自动更新。

使用 .deb, .pkg 等安装包的用户

请下载新版本安装包进行安装。

Docker

DockerHub: ghostchu/peerbanhelper:v7.3.1
阿里云国内镜像加速: registry.cn-hangzhou.aliyuncs.com/ghostchu/peerbanhelper:v7.3.1

@Ghost-chu Ghost-chu requested review from a team as code owners January 12, 2025 20:35
Copy link
Contributor

coderabbitai bot commented Jan 12, 2025

Important

Review skipped

Review was skipped as selected files did not have any reviewable changes.

💤 Files selected but had no reviewable changes (1)
  • install4j/project.install4j~

You can disable this status message by setting the reviews.review_status to false in the CodeRabbit configuration file.

概述

演练

这个拉取请求包含了 PeerBanHelper 项目的多个重要更改。主要修改涉及在多个问题模板中添加新的复选框选项,允许用户确认未仔细检查清单;更新应用版本(从 7.3.0 到 7.0.0),移除 HikariCP 依赖;数据库连接方式的变更,改用直接数据库连接并添加定期数据库优化任务;IP 地址处理的优化;下载器状态管理的调整,以及 Web UI 的界面和本地化改进。这些更改旨在提高项目的性能、可用性和用户体验。

变更

文件路径 变更摘要
.github/ISSUE_TEMPLATE/* 在多个问题模板中添加新的复选框选项,允许用户确认未仔细检查清单
install4j/project.install4j~ 更新应用版本,移除启动标志变量,直接在启动器中配置 VM 参数
pom.xml 项目版本从 7.3.0 更新到 7.3.1,移除 HikariCP 依赖
src/main/java/com/ghostchu/peerbanhelper/PeerBanHelperServer.java BAN_LISTConcurrentHashMap 更改为 ConcurrentSkipListMap,修改 collectPeers 方法返回类型
src/main/java/com/ghostchu/peerbanhelper/database/Database.java 移除 HikariCP 连接池,改用直接数据库连接,添加定期数据库优化任务
webui/* 多个 Vue 组件中调整图表选项、本地化文本和下载器配置

建议的审阅者

  • Gaojianli
  • paulzzh

可能相关的 PR

  • v7.3.0 #880:与用户交互和反馈机制的增强相关,包括全局暂停功能和改进的错误报告

🪧 Tips

Chat

There are 3 ways to chat with CodeRabbit:

  • Review comments: Directly reply to a review comment made by CodeRabbit. Example:
    • I pushed a fix in commit <commit_id>, please review it.
    • Generate unit testing code for this file.
    • Open a follow-up GitHub issue for this discussion.
  • Files and specific lines of code (under the "Files changed" tab): Tag @coderabbitai in a new review comment at the desired location with your query. Examples:
    • @coderabbitai generate unit testing code for this file.
    • @coderabbitai modularize this function.
  • PR comments: Tag @coderabbitai in a new PR comment to ask questions about the PR branch. For the best results, please provide a very specific query, as very limited context is provided in this mode. Examples:
    • @coderabbitai gather interesting stats about this repository and render them as a table. Additionally, render a pie chart showing the language distribution in the codebase.
    • @coderabbitai read src/utils.ts and generate unit testing code.
    • @coderabbitai read the files in the src/scheduler package and generate a class diagram using mermaid and a README in the markdown format.
    • @coderabbitai help me debug CodeRabbit configuration file.

Note: Be mindful of the bot's finite context window. It's strongly recommended to break down tasks such as reading entire modules into smaller chunks. For a focused discussion, use review comments to chat about specific files and their changes, instead of using the PR comments.

CodeRabbit Commands (Invoked using PR comments)

  • @coderabbitai pause to pause the reviews on a PR.
  • @coderabbitai resume to resume the paused reviews.
  • @coderabbitai review to trigger an incremental review. This is useful when automatic reviews are disabled for the repository.
  • @coderabbitai full review to do a full review from scratch and review all the files again.
  • @coderabbitai summary to regenerate the summary of the PR.
  • @coderabbitai generate docstrings to generate docstrings for this PR. (Beta)
  • @coderabbitai resolve resolve all the CodeRabbit review comments.
  • @coderabbitai configuration to show the current CodeRabbit configuration for the repository.
  • @coderabbitai help to get help.

Other keywords and placeholders

  • Add @coderabbitai ignore anywhere in the PR description to prevent this PR from being reviewed.
  • Add @coderabbitai summary to generate the high-level summary at a specific location in the PR description.
  • Add @coderabbitai anywhere in the PR title to generate the title automatically.

CodeRabbit Configuration File (.coderabbit.yaml)

  • You can programmatically configure CodeRabbit by adding a .coderabbit.yaml file to the root of your repository.
  • Please see the configuration documentation for more information.
  • If your editor has YAML language server enabled, you can add the path at the top of this file to enable auto-completion and validation: # yaml-language-server: $schema=https://coderabbit.ai/integrations/schema.v2.json

Documentation and Community

  • Visit our Documentation for detailed information on how to use CodeRabbit.
  • Join our Discord Community to get help, request features, and share feedback.
  • Follow us on X/Twitter for updates and announcements.

Copy link
Contributor

@coderabbitai coderabbitai bot left a comment

Choose a reason for hiding this comment

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

Actionable comments posted: 5

🧹 Nitpick comments (11)
webui/src/locale/zh-CN.ts (1)

35-36: 描述更新清晰地说明了全局暂停模式的影响!

描述的补充很好地说明了启用全局暂停模式后对已封禁 IP 的即时影响。建议考虑在描述中添加一个换行符来提高可读性。

  'globalPauseModel.description':
-    '这将暂停所有下载器的封禁和检查操作,直至下次重启或者取消暂停。已封禁的 IP 地址将全部立刻解除封禁。',
+    '这将暂停所有下载器的封禁和检查操作,直至下次重启或者取消暂停。\n已封禁的 IP 地址将全部立刻解除封禁。',
src/main/java/com/ghostchu/peerbanhelper/util/IPAddressUtil.java (3)

Line range hint 20-24: 建议优化缓存配置以提升性能

考虑到 PR 的性能优化目标,建议对 IP_ADDRESS_CACHE 进行以下优化:

  1. 根据实际使用情况调整 maximumSize
  2. 考虑添加并发级别配置
  3. 可以添加统计监控以便调优

建议参考以下配置:

 private static final Cache<String, IPAddress> IP_ADDRESS_CACHE = CacheBuilder.newBuilder()
     .expireAfterAccess(15, TimeUnit.MINUTES)
-    .maximumSize(100)
+    .maximumSize(1000)
+    .concurrencyLevel(4)
+    .recordStats()
     .softValues()
     .build();

Line range hint 25-29: 建议统一两个缓存的配置

为了保持一致性和便于维护,建议将 IP_WITHOUT_PREFIX_CACHE 的配置与 IP_ADDRESS_CACHE 保持一致。


Line range hint 71-74: 建议改进错误处理机制

当前的错误处理仅记录日志并返回 null,建议:

  1. 添加更详细的错误信息
  2. 考虑使用自定义异常
  3. 添加重试机制

建议参考以下实现:

     try {
         return IP_ADDRESS_CACHE.get(ip, () -> new IPAddressString(ip).toAddress());
     } catch (ExecutionException e) {
-        log.error("Unable to get ipaddress from ip {}", ip, e);
+        log.error("IP地址解析失败 [ip={}, cause={}]", ip, e.getCause().getMessage(), e);
+        if (e.getCause() instanceof IllegalArgumentException) {
+            log.warn("输入的IP地址格式不正确: {}", ip);
+        }
         return null;
     }
src/main/java/com/ghostchu/peerbanhelper/module/impl/rule/AutoRangeBan.java (1)

Line range hint 106-133: 建议优化大规模封禁列表的遍历性能

当前实现在遍历封禁列表时需要进行多次地址转换和前缀计算。对于大规模的封禁列表,这可能会影响性能。

建议考虑以下优化方案:

  1. 缓存转换后的地址和前缀块
  2. 按地址类型(IPv4/IPv6)预先分组
+    // Cache for converted addresses and prefix blocks
+    private final Map<IPAddress, IPAddress> addressCache = new ConcurrentHashMap<>();
+
     @Override
     public @NotNull CheckResult shouldBanPeer(@NotNull Torrent torrent, @NotNull Peer peer, @NotNull Downloader downloader, @NotNull ExecutorService ruleExecuteExecutor) {
         if (isHandShaking(peer)) {
             return pass();
         }
         if (getServer().getBannedPeersDirect().containsKey(peer.getPeerAddress())) {
             return pass();
         }
-        IPAddress peerAddress = peer.getPeerAddress().getAddress().withoutPrefixLength();
+        IPAddress peerAddress = addressCache.computeIfAbsent(
+            peer.getPeerAddress().getAddress(),
+            addr -> {
+                IPAddress converted = addr.withoutPrefixLength();
+                return converted.isIPv4Convertible() ? converted.toIPv4() : converted;
+            }
+        );
-        if (peerAddress.isIPv4Convertible()) {
-            peerAddress = peerAddress.toIPv4();
-        }
src/main/java/com/ghostchu/peerbanhelper/downloader/impl/qbittorrent/AbstractQbittorrent.java (1)

165-166: 建议本地化错误消息

错误日志消息"Failed to check login status"应该使用Lang类中的翻译键,以保持与应用程序的国际化一致。

-            log.error("Failed to check login status", e);
+            log.error(tlUI(Lang.DOWNLOADER_QB_LOGIN_CHECK_FAILED, e.getMessage()), e);
.github/ISSUE_TEMPLATE/any_other.yml (1)

37-38: 复选框的添加有助于提高问题报告的质量!

这个复选框的添加是个很好的想法,可以帮助识别没有认真阅读检查清单的用户。不过建议将此选项移到检查清单的最后一项,以避免用户在看到这个选项后就不再继续阅读后面的重要条款。

-        - label: "我没有检查这个检查清单,只是闭眼选中了所有的复选框,请关闭这个 Issue (I have not read these checkboxes and therefore I just ticked them all, Please close this issue)"
-          required: false
         - label: "我同意遵守 PBH-BTN 包容性条约...
           required: false
+        - label: "我没有检查这个检查清单,只是闭眼选中了所有的复选框,请关闭这个 Issue (I have not read these checkboxes and therefore I just ticked them all, Please close this issue)"
+          required: false
.github/ISSUE_TEMPLATE/web_ui.yml (1)

74-75: 保持模板一致性的同时优化选项顺序

建议与 any_other.yml 模板保持一致,将此选项移至检查清单的最后,确保用户在看到此选项前已阅读所有重要条款。

-        - label: "我没有检查这个检查清单,只是闭眼选中了所有的复选框,请关闭这个 Issue (I have not read these checkboxes and therefore I just ticked them all, Please close this issue)"
-          required: false
         - label: "我同意遵守 PBH-BTN 包容性条约...
           required: false
+        - label: "我没有检查这个检查清单,只是闭眼选中了所有的复选框,请关闭这个 Issue (I have not read these checkboxes and therefore I just ticked them all, Please close this issue)"
+          required: false
webui/src/views/charts/components/banTrends.vue (1)

102-113: 代码实现正确,建议提取颜色常量!

代码实现遵循了 Vue.js 的最佳实践,暗色模式的切换逻辑清晰。不过建议将颜色值提取为常量,以便统一管理和复用。

+// 在单独的配置文件中定义颜色常量
+const CHART_COLORS = {
+  DARK: {
+    TOOLTIP_BG: '#333335',
+    TEXT: 'rgba(255, 255, 255, 0.7)',
+    BACKGROUND: 'rgba(0, 0, 0, 0.0)'
+  },
+  LIGHT: {
+    TOOLTIP_BG: '#ffffff'
+  }
+}

 const usedOption = computed(() => ({
   tooltip: {
     trigger: 'axis',
-    backgroundColor: darkStore.isDark ? '#333335' : '#ffffff',
-    borderColor: darkStore.isDark ? '#333335' : '#ffffff',
+    backgroundColor: darkStore.isDark ? CHART_COLORS.DARK.TOOLTIP_BG : CHART_COLORS.LIGHT.TOOLTIP_BG,
+    borderColor: darkStore.isDark ? CHART_COLORS.DARK.TOOLTIP_BG : CHART_COLORS.LIGHT.TOOLTIP_BG,
     textStyle: {
-      color: darkStore.isDark ? 'rgba(255, 255, 255, 0.7)' : undefined
+      color: darkStore.isDark ? CHART_COLORS.DARK.TEXT : undefined
     }
   },
-  backgroundColor: darkStore.isDark ? 'rgba(0, 0, 0, 0.0)' : undefined,
+  backgroundColor: darkStore.isDark ? CHART_COLORS.DARK.BACKGROUND : undefined,
   ...chartOptions.value
 }))
webui/src/views/charts/components/ispPie.vue (1)

Line range hint 148-180: 图表配置优化建议

  1. 图例宽度硬编码为 100px 可能在不同屏幕尺寸下不够灵活。
  2. 阴影颜色未考虑深色模式。
  3. 饼图中心位置可以更具响应性。

建议进行以下优化:

 const chartOption = ref({
   legend: {
     orient: 'vertical',
     left: 'right',
     type: 'scroll',
     right: 10,
     top: 20,
     bottom: 20,
     data: [] as string[],
     textStyle: {
       overflow: 'truncate',
-      width: 100
+      width: '20%'
     },
     tooltip: {
       show: true
     }
   },
   series: [
     {
       name: '',
       type: 'pie',
       radius: '55%',
-      center: ['50%', '60%'],
+      center: ['40%', '60%'],
       data: [] as { name: string; value: number }[],
       emphasis: {
         itemStyle: {
           shadowBlur: 10,
           shadowOffsetX: 0,
-          shadowColor: 'rgba(0, 0, 0, 0.5)'
+          shadowColor: computed(() => 
+            darkStore.isDark ? 'rgba(255, 255, 255, 0.3)' : 'rgba(0, 0, 0, 0.5)'
+          )
         }
       }
     }
   ]
 })
src/main/java/com/ghostchu/peerbanhelper/database/Database.java (1)

80-80: 移除多余的分号

第 80 行的分号是多余的,没有任何作用,建议移除。

-                    ;
📜 Review details

Configuration used: CodeRabbit UI
Review profile: CHILL
Plan: Pro

📥 Commits

Reviewing files that changed from the base of the PR and between 4d0cdf3 and f49b669.

📒 Files selected for processing (22)
  • .github/ISSUE_TEMPLATE/any_other.yml (1 hunks)
  • .github/ISSUE_TEMPLATE/bug_report.yml (1 hunks)
  • .github/ISSUE_TEMPLATE/web_ui.yml (1 hunks)
  • install4j/project.install4j~ (6 hunks)
  • pom.xml (1 hunks)
  • src/main/java/com/ghostchu/peerbanhelper/PeerBanHelperServer.java (6 hunks)
  • src/main/java/com/ghostchu/peerbanhelper/database/Database.java (3 hunks)
  • src/main/java/com/ghostchu/peerbanhelper/downloader/impl/qbittorrent/AbstractQbittorrent.java (4 hunks)
  • src/main/java/com/ghostchu/peerbanhelper/ipdb/IPDB.java (5 hunks)
  • src/main/java/com/ghostchu/peerbanhelper/module/impl/rule/AutoRangeBan.java (1 hunks)
  • src/main/java/com/ghostchu/peerbanhelper/module/impl/webapi/PBHDownloaderController.java (1 hunks)
  • src/main/java/com/ghostchu/peerbanhelper/util/IPAddressUtil.java (1 hunks)
  • webui/src/api/model/downloader.ts (0 hunks)
  • webui/src/locale/en-US.ts (1 hunks)
  • webui/src/locale/zh-CN.ts (1 hunks)
  • webui/src/views/charts/components/banTrends.vue (2 hunks)
  • webui/src/views/charts/components/fieldPie.vue (1 hunks)
  • webui/src/views/charts/components/ispPie.vue (1 hunks)
  • webui/src/views/charts/components/traffic.vue (2 hunks)
  • webui/src/views/charts/components/trends.vue (2 hunks)
  • webui/src/views/dashboard/components/editDownloaderModal.vue (2 hunks)
  • webui/src/views/rule-management/components/subscribe/logModal.vue (2 hunks)
💤 Files with no reviewable changes (1)
  • webui/src/api/model/downloader.ts
🧰 Additional context used
📓 Learnings (1)
src/main/java/com/ghostchu/peerbanhelper/module/impl/webapi/PBHDownloaderController.java (1)
Learnt from: Ghost-chu
PR: PBH-BTN/PeerBanHelper#875
File: src/main/java/com/ghostchu/peerbanhelper/module/impl/webapi/PBHDownloaderController.java:85-93
Timestamp: 2025-01-08T12:51:25.331Z
Learning: Avoid suggesting alternative implementations that achieve the same result as the existing code, especially when the original code is already using appropriate patterns like short-circuit evaluation.
⏰ Context from checks skipped due to timeout of 90000ms (2)
  • GitHub Check: Build_Installers / install4jc
  • GitHub Check: Build_Docker
🔇 Additional comments (26)
webui/src/locale/en-US.ts (1)

34-34: 中英文翻译保持一致性,描述准确!

英文版本的描述变更与中文版本保持了良好的一致性,准确传达了全局暂停模式的功能影响。

src/main/java/com/ghostchu/peerbanhelper/util/IPAddressUtil.java (1)

69-69: 代码简化优化得当!

Lambda 表达式的简化提高了代码的可读性,同时保持了原有功能。

src/main/java/com/ghostchu/peerbanhelper/module/impl/rule/AutoRangeBan.java (1)

99-101: 使用直接访问方式提高性能

使用 getBannedPeersDirect() 替代 getBannedPeers() 是一个很好的性能优化。这种直接访问方式避免了不必要的数据复制,有助于提高读取性能。

src/main/java/com/ghostchu/peerbanhelper/downloader/impl/qbittorrent/AbstractQbittorrent.java (3)

3-3: 导入声明看起来不错!

新增的Jackson和Lombok注解导入合理地支持了新的功能实现。

Also applies to: 28-30


150-163: 登录验证逻辑得到了改进!

通过检查buildInfo而不是version来验证登录状态是一个更可靠的方案,同时添加了适当的空值检查。


373-391: QBittorrentBuildInfo类的设计很规范!

  1. 使用Lombok注解减少了样板代码
  2. 使用JsonProperty注解确保了与API响应的正确映射
  3. 字段设计完整地覆盖了qBittorrent的构建信息
webui/src/views/rule-management/components/subscribe/logModal.vue (2)

46-48: 导入语句重组符合最佳实践

updateTypegetColor的导入移至导入部分顶部,提高了代码的组织性和可读性。


6-6: 请验证模态框宽度调整是否合适

模态框宽度从35vw调整到30vw,请确认:

  1. 内容是否会在较小屏幕上被截断
  2. 在暗色模式下是否仍然正常显示
webui/src/views/charts/components/banTrends.vue (1)

132-132: 格式调整,无需修改。

webui/src/views/charts/components/trends.vue (1)

112-112: 代码格式调整,提高了可读性。

webui/src/views/charts/components/traffic.vue (3)

Line range hint 114-139: 实现完善,格式化函数处理得当!

tooltip 的配置完整,格式化函数的实现清晰。暗色模式的处理与其他组件保持一致,很好地保证了用户体验的统一性。


140-140: 代码格式调整,提高了可读性。


141-141: 变量声明正确。

webui/src/views/charts/components/fieldPie.vue (3)

100-113: 实现规范,tooltip 文本换行处理得当!

代码实现与其他图表组件保持一致,特别是通过 word-wrap:break-all 很好地处理了 tooltip 中的长文本换行问题。


114-114: 代码格式调整,提高了可读性。


115-115: 变量声明正确。

src/main/java/com/ghostchu/peerbanhelper/module/impl/webapi/PBHDownloaderController.java (1)

159-159: 代码逻辑合理,修改看起来不错。

代码修改正确,逻辑清晰,符合预期。

src/main/java/com/ghostchu/peerbanhelper/ipdb/IPDB.java (2)

436-440: 🛠️ Refactor suggestion

避免使用 @SneakyThrows 注解

使用 @SneakyThrows 可能会隐藏受检异常,导致异常处理不明确。建议直接抛出异常或在方法内部适当处理。

-        @SneakyThrows
         @Override
         public DecodedValue get(CacheKey cacheKey, Loader loader) throws IOException {
             return cache.get(cacheKey, () -> loader.load(cacheKey));
         }

Likely invalid or redundant comment.


95-107: 确认移除缓存后对性能的影响

query 方法中,缓存机制被移除,改为每次直接查询 IPGeoData。请验证此更改是否会对系统性能产生影响,特别是在高并发环境下。

您可以使用以下脚本来评估 query 方法的调用频率和可能的性能影响:

✅ Verification successful

移除缓存是安全的,对性能影响可控

经过代码分析,IPDB.query 的调用模式显示:

  • 查询都在异步或惰性加载上下文中执行
  • 没有发现高频率调用的场景
  • 系统已经通过 ThreadPool 和 LazyLoad 实现了性能优化
🏁 Scripts executed

The following scripts were executed for the analysis:

Script:

#!/bin/bash
# 描述:统计 'query' 方法的调用次数

# 测试:在代码库中查找所有对 'ipdb.query(' 的调用。期望:了解调用频率。

rg -c "ipdb\.query\(" src/

Length of output: 267


Script:

#!/bin/bash
# Show context of ipdb.query calls
echo "=== PBHPeerController.java ==="
rg "ipdb\.query\(" src/main/java/com/ghostchu/peerbanhelper/module/impl/webapi/PBHPeerController.java -B 2 -A 2

echo -e "\n=== PBHChartController.java ==="
rg "ipdb\.query\(" src/main/java/com/ghostchu/peerbanhelper/module/impl/webapi/PBHChartController.java -B 2 -A 2

echo -e "\n=== PeerBanHelperServer.java ==="
rg "ipdb\.query\(" src/main/java/com/ghostchu/peerbanhelper/PeerBanHelperServer.java -B 2 -A 2

# Look for configuration files
echo -e "\n=== Configuration Files ==="
fd "application.*yml|application.*properties" --type f

Length of output: 1387

src/main/java/com/ghostchu/peerbanhelper/PeerBanHelperServer.java (3)

85-85: 数据结构优化:使用 ConcurrentSkipListMap 替代 ConcurrentHashMap

使用 ConcurrentSkipListMap 是一个很好的改进,它提供了以下优势:

  • 有序迭代,对于监控和调试更友好
  • 在高并发场景下表现良好
  • 适合范围操作

487-487: 代码格式优化:添加了缺失的空行

添加空行提高了代码的可读性,使逻辑块之间的分隔更清晰。

Also applies to: 527-527


745-747: 改进错误处理:登录失败时返回 null

将登录失败时的返回值从空 Map 改为 null 是一个更好的设计:

  • 更明确地表示失败状态
  • 避免创建不必要的空对象
  • 强制调用者处理失败情况

Also applies to: 768-768

install4j/project.install4j~ (1)

40-40: 优化了 JVM 参数配置

VM 参数的更新很合理,包含了:

  • 内存管理优化 (-Xmx512M, -Xss512k)
  • GC 优化 (-XX:+UseG1GC, -XX:+UseStringDeduplication)
  • 系统属性配置

Also applies to: 54-54, 68-68, 82-82, 96-96

webui/src/views/dashboard/components/editDownloaderModal.vue (2)

16-16: 优化选择器宽度

将选择器宽度从 10em 增加到 11em 改善了用户体验:

  • 防止文本截断
  • 提高可读性

46-52: 更新暂停状态字段路径

将暂停状态字段从 paused 更新为 config.paused 使其:

  • 结构更清晰
  • 与后端数据模型保持一致
  • 便于配置管理
pom.xml (1)

9-9: 版本号更新

版本号从 7.3.0 更新到 7.3.1 符合语义化版本规范:

  • 修复版本号递增
  • 与更新内容(bug修复和性能优化)相符

.github/ISSUE_TEMPLATE/bug_report.yml Outdated Show resolved Hide resolved
webui/src/views/charts/components/trends.vue Show resolved Hide resolved
webui/src/views/charts/components/ispPie.vue Show resolved Hide resolved
install4j/project.install4j~ Outdated Show resolved Hide resolved
Ghost-chu and others added 2 commits January 13, 2025 04:43
Co-authored-by: coderabbitai[bot] <136622811+coderabbitai[bot]@users.noreply.github.com>
@Ghost-chu Ghost-chu changed the title v4.3.1 v7.3.1 Jan 12, 2025
Copy link
Contributor

@coderabbitai coderabbitai bot left a comment

Choose a reason for hiding this comment

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

Actionable comments posted: 1

🔭 Outside diff range comments (1)
src/main/java/com/ghostchu/peerbanhelper/database/Database.java (1)

Line range hint 81-107: 数据库维护操作安全性建议

数据库维护逻辑存在以下潜在问题:

  1. 备份文件使用固定名称可能导致并发问题
  2. 备份文件在异常情况下可能未被清理
  3. VACUUM 操作可能长时间阻塞数据库

建议改进:

-                                File outputBackup = new File(file.getParentFile(), file.getName() + ".bak.gz");
+                                String backupName = String.format("%s_%d.bak.gz", file.getName(), System.currentTimeMillis());
+                                File outputBackup = new File(file.getParentFile(), backupName);
                                 try {
                                     backupDatabase(file, outputBackup);
                                     long fileSize = file.length();
-                                    stmt.executeUpdate("VACUUM;");
+                                    // 设置超时以防止长时间阻塞
+                                    stmt.setQueryTimeout(3600);  // 1小时超时
+                                    stmt.executeUpdate("VACUUM;");
                                     long newFileSize = file.length();
                                     log.info(tlUI(Lang.SQLITE_VACUUM_SUCCESS, MsgUtil.humanReadableByteCountBin(fileSize), MsgUtil.humanReadableByteCountBin(newFileSize)));
                                 } catch (IOException e) {
                                     log.warn(tlUI(Lang.SQLITE_VACUUM_BACKUP_FAILED), e);
+                                } catch (SQLException e) {
+                                    log.error("VACUUM 操作失败", e);
                                 } finally {
-                                    outputBackup.delete();
+                                    if (!outputBackup.delete()) {
+                                        log.warn("无法删除备份文件: {}", outputBackup.getAbsolutePath());
+                                        outputBackup.deleteOnExit();
+                                    }
                                 }
🧹 Nitpick comments (1)
src/main/java/com/ghostchu/peerbanhelper/database/Database.java (1)

73-73: 数据库连接管理优化建议

移除 HikariCP 连接池简化了实现,但建议添加以下安全措施:

  1. 设置连接超时参数
  2. 添加连接验证逻辑
  3. 实现重连机制
-        Connection rawConnection = DriverManager.getConnection("jdbc:sqlite:" + file);
+        String jdbcUrl = "jdbc:sqlite:" + file;
+        Properties props = new Properties();
+        props.setProperty("timeout", "30");
+        Connection rawConnection = DriverManager.getConnection(jdbcUrl, props);
📜 Review details

Configuration used: CodeRabbit UI
Review profile: CHILL
Plan: Pro

📥 Commits

Reviewing files that changed from the base of the PR and between f49b669 and ef76ec8.

📒 Files selected for processing (2)
  • .github/ISSUE_TEMPLATE/bug_report.yml (1 hunks)
  • src/main/java/com/ghostchu/peerbanhelper/database/Database.java (2 hunks)
🚧 Files skipped from review as they are similar to previous changes (1)
  • .github/ISSUE_TEMPLATE/bug_report.yml
⏰ Context from checks skipped due to timeout of 90000ms (1)
  • GitHub Check: Build_Installers / install4jc

@Ghost-chu Ghost-chu merged commit d1e411f into release Jan 13, 2025
19 checks passed
This was referenced Jan 13, 2025
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.

3 participants