Skip to content

feat(hole): add favorite/subscription count stats #183

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

Open
wants to merge 2 commits into
base: main
Choose a base branch
from

Conversation

Acture
Copy link

@Acture Acture commented May 10, 2025

实现了洞的收藏和订阅计数功能,以及相关的计数更新逻辑。

变更内容

  • 新增字段:favorite_count / subscription_count 到 Hole 模型,默认值为 0
  • 新增方法:recalculate_stats(),支持收藏/订阅数量的聚合更新(含 DB + cache)
  • 优化订阅操作:
    • 改进AddUserSubscription确保幂等性
    • 添加RemoveUserSubscription处理取消订阅
  • 增强收藏管理,正确更新计数
  • 使用dbresolver.Write保证写事务一致性
  • 更新相关测试,覆盖统计逻辑及字段同步

为什么需要这个功能

  • 后端补充收藏/订阅总数,用于前端热度展示
  • 避免每次请求实时计算,走持久化 + lazy update 模式提高性能

测试情况

已添加相关测试用例并确保全部通过,覆盖了计数逻辑的各种情况。

Closes #182

Acture added 2 commits May 11, 2025 06:31
- Introduced `FavoriteCount` and `SubscriptionCount` fields to the `Hole` model with default values.
- Added `RecalculateStats` method to update favorite and subscription stats for a hole, including database and cache updates.
- Updated tests to cover recalculation logic and validate the new stats functionality.
…ing with transactional updates

- Added `RemoveUserSubscription` to handle subscription removal with count updates.
- Improved `AddUserSubscription` to ensure idempotency and update subscription count only when necessary.
- Updated favorite management to include count adjustments for holes and favorite groups during add/remove operations.
- Applied `dbresolver.Write` to enforce write transactions for database consistency.

Signed-off-by: acture <[email protected]>
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.

[Feature Request] get hole的接口返回值中增加hole的收藏订阅总数
1 participant