Skip to content

feat: add download-count sorting to plugin marketplace - #9570

Closed
Sisyphbaous-DT-Project wants to merge 1 commit into
AstrBotDevs:masterfrom
Sisyphbaous-DT-Project:feat/market-download-sort
Closed

feat: add download-count sorting to plugin marketplace#9570
Sisyphbaous-DT-Project wants to merge 1 commit into
AstrBotDevs:masterfrom
Sisyphbaous-DT-Project:feat/market-download-sort

Conversation

@Sisyphbaous-DT-Project

@Sisyphbaous-DT-Project Sisyphbaous-DT-Project commented Aug 6, 2026

Copy link
Copy Markdown
Contributor

Motivation / 动机

The plugin marketplace already exposes and displays download_count, but the marketplace sort menu does not provide a way to order plugins by downloads. Users must currently rely on the default recommendation order, stars, author, or update time when looking for widely used plugins.

This change adds download-count sorting while preserving the existing default recommendation behavior and all existing sort modes.

Modifications / 改动点

  • Add a pure sortMarketPluginsByDownloads utility for frontend-local sorting.
  • Add a Downloads option to the marketplace sort control.
  • Support descending and ascending order through the existing sort direction control.
  • Keep plugins without a valid download count at the end in both directions.
  • Preserve the original order for equal counts and unknown counts without mutating the input array or plugin objects.
  • Add localized labels for zh-CN, en-US, and ru-RU.
  • Add focused Node tests covering normal values, zero, invalid and missing values, negative values, numeric strings, decimals, stability, and immutability.

The implementation intentionally keeps sorting on the frontend and does not change backend routes, OpenAPI definitions, generated API clients, dependencies, or the default recommendation order.

  • This is NOT a breaking change. / 这不是一个破坏性变更。

Screenshots or Test Results / 运行截图或测试结果

Verification Steps

node --test dashboard/tests/marketPluginSort.test.mjs
# 9 passed

node --test dashboard/tests/*.test.mjs
# 45 passed

cd dashboard
./node_modules/.bin/vue-tsc --noEmit
# passed

npx --yes pnpm@10.28.2 run build
# passed

cd ..
git diff --check
# passed

Additional checks completed:

  • Parsed all three modified locale JSON files successfully.
  • Verified the sorting utility with additional randomized property checks.
  • Confirmed all changed files use LF line endings.

Manual UI Verification

  • Select Downloads in the marketplace sort menu and verify descending order by default.
  • Toggle the direction control and verify ascending order.
  • Verify plugins without a download count remain at the end in both directions.
  • Verify search, category filtering, pagination, and the existing default, stars, author, and updated sorting modes remain unchanged.
  • Verify the label renders correctly in Chinese, English, and Russian, including narrow-screen layout.

Checklist / 检查清单

  • 😊 This feature has been discussed with the maintainers through an Issue or other channel. / 如果 PR 中有新加入的功能,已经通过 Issue / 邮件等方式和维护者讨论过。
  • 👀 The changes have been manually verified and screenshots have been provided above. / 我的更改经过了手动验证,并已在上方提供截图。
  • 🤓 No new dependencies were introduced. / 未引入新的依赖。
  • 😮 No malicious code was introduced. / 未引入恶意代码。

Summary by Sourcery

Add download-count-based sorting to the plugin marketplace while keeping existing sort modes and behavior unchanged.

New Features:

  • Introduce a Downloads option in the marketplace sort menu that orders plugins by their download counts.

Enhancements:

  • Add a stable, non-mutating frontend utility to sort marketplace plugins by normalized download counts, handling missing and invalid values gracefully.

Tests:

  • Add focused Node tests covering sorting by downloads, handling of edge-case values, stability, and immutability of the sorting utility.

为插件市场现有的前端本地排序补充下载量选项,复用已规范化的 download_count,不改变默认推荐顺序、后端接口和 OpenAPI。

新增稳定且不修改输入的下载量排序工具:支持升降序、未知值双向置底、非法值兜底及相同值原始顺序保留;接入市场排序控件并补齐中、英、俄三语文案。

新增 9 项专项单元测试,覆盖正常排序、零值、缺失与非法值、负数、数字字符串、小数、稳定性和输入不可变。验证通过 45 项 Dashboard Node 测试、额外性质检查、三语 JSON 校验、Vue 类型检查和生产构建。
@dosubot dosubot Bot added size:M This PR changes 30-99 lines, ignoring generated files. area:webui The bug / feature is about webui(dashboard) of astrbot. feature:plugin The bug / feature is about AstrBot plugin system. labels Aug 6, 2026

@sourcery-ai sourcery-ai Bot left a comment

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.

Hey - I've left some high level feedback:

  • In marketPluginSort.mjs, you manually enforce stability via index tracking even though modern engines already provide stable Array.prototype.sort; consider removing the index plumbing to simplify the comparator and reduce per-item allocations.
  • The normalizeDownloadCount helper silently normalizes negatives to zero and treats NaN/Infinity as unknown; if this is relying on backend invariants, it may be worth tightening the accepted input range or documenting this behavior near the function to avoid surprising ordering if backend data changes.
Prompt for AI Agents
Please address the comments from this code review:

## Overall Comments
- In `marketPluginSort.mjs`, you manually enforce stability via index tracking even though modern engines already provide stable `Array.prototype.sort`; consider removing the index plumbing to simplify the comparator and reduce per-item allocations.
- The `normalizeDownloadCount` helper silently normalizes negatives to zero and treats `NaN`/Infinity as unknown; if this is relying on backend invariants, it may be worth tightening the accepted input range or documenting this behavior near the function to avoid surprising ordering if backend data changes.

Sourcery is free for open source - if you like our reviews please consider sharing them ✨
Help me be more useful! Please click 👍 or 👎 on each comment and I'll use the feedback to improve your reviews.

@Sisyphbaous-DT-Project

Sisyphbaous-DT-Project commented Aug 6, 2026

Copy link
Copy Markdown
Contributor Author

The explicit index tie-breaker intentionally guarantees deterministic ordering, while the normalization behavior mirrors the existing marketplace store and is covered by focused tests, so we’ll keep the current implementation.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

area:webui The bug / feature is about webui(dashboard) of astrbot. feature:plugin The bug / feature is about AstrBot plugin system. size:M This PR changes 30-99 lines, ignoring generated files.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant