-
-
Notifications
You must be signed in to change notification settings - Fork 101
New issue
Have a question about this project? # for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “#”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? # to your account
feat: detect private torrents on qBittorrents v4.x #477
feat: detect private torrents on qBittorrents v4.x #477
Conversation
WalkthroughThe changes introduced in this pull request enhance the handling of private torrents in the downloader by implementing caching mechanisms and asynchronous processing. A new cache is added to store the privacy status of torrents, reducing API calls. The retrieval of torrent details is optimized using an Changes
Assessment against linked issues
Possibly related PRs
Poem
Recent review detailsConfiguration used: CodeRabbit UI Files selected for processing (4)
Files skipped from review as they are similar to previous changes (3)
Additional context usedLearnings (1)
Additional comments not posted (5)
Thank you for using CodeRabbit. We offer it for free to the OSS community and would appreciate your support in helping us grow. If you find it useful, would you consider giving us a shout-out on your favorite social media? TipsChatThere are 3 ways to chat with CodeRabbit:
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)
Other keywords and placeholders
CodeRabbit Configuration File (
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Actionable comments posted: 0
Outside diff range and nitpick comments (1)
src/main/java/com/ghostchu/peerbanhelper/downloader/impl/qbittorrent/QBittorrentEE.java (1)
230-257
: Good implementation of the caching logic!
- The method correctly checks the cache first and queries the API only if necessary.
- Storing the retrieved privacy status in the cache helps avoid unnecessary API calls in the future.
Consider improving the error handling by propagating the exception or providing a fallback value instead of just logging the error. This would allow the caller to handle the error appropriately.
Review details
Configuration used: CodeRabbit UI
Review profile: CHILL
Files selected for processing (6)
- src/main/java/com/ghostchu/peerbanhelper/downloader/impl/qbittorrent/QBittorrent.java (3 hunks)
- src/main/java/com/ghostchu/peerbanhelper/downloader/impl/qbittorrent/QBittorrentEE.java (6 hunks)
- webui/src/components/forms/qbittorrent.vue (0 hunks)
- webui/src/components/forms/qbittorrentee.vue (0 hunks)
- webui/src/views/dashboard/locale/en-US.ts (0 hunks)
- webui/src/views/dashboard/locale/zh-CN.ts (0 hunks)
Files not reviewed due to no reviewable changes (4)
- webui/src/components/forms/qbittorrent.vue
- webui/src/components/forms/qbittorrentee.vue
- webui/src/views/dashboard/locale/en-US.ts
- webui/src/views/dashboard/locale/zh-CN.ts
Additional context used
Learnings (1)
src/main/java/com/ghostchu/peerbanhelper/downloader/impl/qbittorrent/QBittorrentEE.java (1)
Learnt from: Ghost-chu PR: PBH-BTN/PeerBanHelper#400 File: src/main/java/com/ghostchu/peerbanhelper/downloader/impl/qbittorrent/QBittorrentEE.java:134-142 Timestamp: 2024-08-30T18:57:41.277Z Learning: Ghost-chu prefers not to receive logging suggestions in code reviews.
Additional comments not posted (10)
src/main/java/com/ghostchu/peerbanhelper/downloader/impl/qbittorrent/QBittorrent.java (5)
37-38
: LGTM!The imports are necessary for the usage of concurrency utilities and stream operations in the code changes.
48-55
: LGTM!The introduction of the
isPrivateCacheMap
,isPrivateExecutorService
, andisPrivateSemaphore
fields is a good approach to optimize performance and limit concurrent requests.
- The
isPrivateCacheMap
efficiently caches the privacy status of torrents, reducing the need for repeated API calls.- The
isPrivateExecutorService
allows for concurrent processing of API requests, improving performance.- The
isPrivateSemaphore
effectively limits the number of concurrent requests to prevent overloading the server.
169-185
: LGTM!The use of
CompletableFuture
for asynchronous processing of private field checks is a good approach to improve performance.
- The
isPrivateSemaphore
is properly acquired and released to limit concurrent access.- The
futures
list stores theCompletableFuture
objects for later processing.- The code segment effectively handles the case when the
is_private
field is missing and private torrents should be ignored.
190-204
: LGTM!The processing of the
CompletableFuture
results using a stream pipeline is a clean and efficient approach.
CompletableFuture.allOf
ensures that all the asynchronous tasks are completed before processing the results.- The stream pipeline effectively filters and maps the
QBTorrent
objects toTorrentImpl
objects, extracting the necessary fields.- The code segment correctly handles the case when
ignorePrivate
is true and filters out private torrents.
209-236
: LGTM!The
checkAndSetPrivateField
method is a well-implemented solution for checking and setting the private field of aQBTorrent
object.
- The use of caching in the
isPrivateCacheMap
avoids repeated API calls for the same torrent, improving performance.- The synchronization of the
isPrivateCacheMap
usingsynchronized
ensures thread safety when updating the cache.- The error handling and logging are appropriate for the API request.
src/main/java/com/ghostchu/peerbanhelper/downloader/impl/qbittorrent/QBittorrentEE.java (5)
38-39
: LGTM!The new imports are necessary for the changes made in the file and look good.
50-57
: Great job with the caching and concurrency handling!
- The
LinkedHashMap
cache implementation with a maximum size and automatic removal of the oldest entry is a good approach to limit memory usage.- Using
ExecutorService
to manage concurrent API requests is a good practice to improve performance and avoid blocking the main thread.- The
Semaphore
is used correctly to limit the number of concurrent accesses and prevent overwhelming the API.
190-226
: Excellent implementation of asynchronous privacy checks!
- Using
CompletableFuture
to asynchronously check the privacy status is a good approach to improve performance and avoid blocking the main thread.- The
isPrivateSemaphore
is used correctly to limit the number of concurrent accesses.- Waiting for all futures to complete using
CompletableFuture.allOf
ensures that all privacy checks are done before proceeding.- Filtering the results based on the
ignorePrivate
configuration is implemented correctly.
481-481
: LGTM!The new
ignorePrivate
field is added correctly to theConfig
class.
500-500
: LGTM!The
ignorePrivate
field is correctly read from and written to the YAML configuration in theConfig
class.Also applies to: 516-516
src/main/java/com/ghostchu/peerbanhelper/downloader/impl/qbittorrent/QBittorrent.java
Outdated
Show resolved
Hide resolved
src/main/java/com/ghostchu/peerbanhelper/downloader/impl/qbittorrent/QBittorrent.java
Outdated
Show resolved
Hide resolved
src/main/java/com/ghostchu/peerbanhelper/downloader/impl/qbittorrent/QBittorrent.java
Outdated
Show resolved
Hide resolved
src/main/java/com/ghostchu/peerbanhelper/downloader/impl/qbittorrent/QBittorrent.java
Outdated
Show resolved
Hide resolved
src/main/java/com/ghostchu/peerbanhelper/downloader/impl/qbittorrent/QBittorrent.java
Outdated
Show resolved
Hide resolved
src/main/java/com/ghostchu/peerbanhelper/downloader/impl/qbittorrent/QBittorrent.java
Outdated
Show resolved
Hide resolved
src/main/java/com/ghostchu/peerbanhelper/downloader/impl/qbittorrent/QBittorrent.java
Outdated
Show resolved
Hide resolved
src/main/java/com/ghostchu/peerbanhelper/downloader/impl/qbittorrent/QBittorrent.java
Outdated
Show resolved
Hide resolved
补丁更新到 PR 后,请注意合并上游 master 的新更改。合并完成后进行 CI 测试。 |
已处理,不过 patch 文件不像是标准的 git format-patch,里面没有 From: 之类的信息, 如果对此有问题的话(例如上面的 Unverified),可以回复我做 |
@coderabbitai review |
Actions performedReview triggered.
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
WebUI 的 Lint 检查未通过,需要修复一下
请合并一下上游更改,PR 冲突了 |
已合并,不过先前的 patch 文件里将 |
LGTM |
为 qBittorrent 4.x 添加私有种子检测支持。
qBittorrent 在 5.x 上为
/api/v2/torrents/info
API 返回了is_private
字段,对于接口未返回该字段的情况(如 qBittorrent 4.x),现在会再调用/api/v2/torrents/properties
API 获取 torrent 的完整信息,得到is_private
字段,从而在低版本 qBittorrent 上支持过滤私有 torrent。为了减少请求开销,上述功能仅在需要时执行,最大并发 5 线程请求 qBittorrent 的 API 接口,且会将结果缓存,避免重复请求。
相关的粗略性能调试结果可参考 #472 (comment) ,本 PR 的测试用构建产物可在 这里 获取。
Fixes #472 .
Disclaimer: 本 PR 内的修改包含使用 ChatGPT 生成的源代码,若该行为不符合项目的贡献规范,可以关闭本 PR。
Summary by CodeRabbit
New Features
Bug Fixes