Skip to content

Release v1.3.7#85

Merged
Aliothmoon merged 2 commits into
mainfrom
dev
Apr 1, 2026
Merged

Release v1.3.7#85
Aliothmoon merged 2 commits into
mainfrom
dev

Conversation

@Aliothmoon

@Aliothmoon Aliothmoon commented Apr 1, 2026

Copy link
Copy Markdown
Collaborator

Summary by Sourcery

使用 Redis HyperLogLog 和更安全的请求元数据处理方式,更准确地统计唯一资源请求以及日活用户数。

Bug 修复:

  • 通过仅在“每个资源、每个 IP、每天”维度上进行一次计数,避免资源浏览量被重复统计。
  • 在将请求中提取的字符串发送到后台收集器之前先进行克隆,防止潜在的数据竞争或意外交叉引用问题。

功能增强:

  • 为“每个资源的每日请求”引入 HyperLogLog 键,用于跟踪唯一请求 IP,并据此控制何时增加排行榜分数。
  • 确保资源浏览计数器和日活用户记录都在一致的保留期后过期。
Original summary in English

Summary by Sourcery

Track unique resource requests and daily active users more accurately using Redis HyperLogLog and safer request metadata handling.

Bug Fixes:

  • Avoid overcounting resource views by only incrementing per unique IP per resource per day.
  • Prevent potential data races or unintended aliasing by cloning request-derived strings before sending them to background collectors.

Enhancements:

  • Introduce per-resource-per-day HyperLogLog keys to track unique request IPs and control when ranking scores are incremented.
  • Ensure both resource view counters and daily active user records expire after a consistent retention period.

@sourcery-ai sourcery-ai Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

Hey - 我在这里给出了一些高层面的反馈:

  • 建议捕获并至少记录 viewKeyhllKeyExpire 调用的错误,这样设置 TTL 失败的情况就不会被忽略。
  • 由于 time.Now().Format("20060102") 是在收集器循环内部计算的,如果某个逻辑事件跨越了午夜,同一个事件可能会被划分到不同的日期桶中;建议在事件入队时就计算日期,并通过 channel 传递该日期。
给 AI 代理的提示
Please address the comments from this code review:

## Overall Comments
- Consider capturing and at least logging errors from the `Expire` calls on both `viewKey` and `hllKey` so that failures to set TTLs don’t go unnoticed.
- Because `time.Now().Format("20060102")` is evaluated inside the collector loop, the same logical event could be bucketed into different dates if it straddles midnight; consider computing the date when the event is enqueued and passing it through the channel instead.

Sourcery 对开源项目是免费的——如果你觉得我们的评审有帮助,欢迎分享 ✨
帮我变得更有用!请在每条评论上点 👍 或 👎,我会根据你的反馈来改进评审质量。
Original comment in English

Hey - I've left some high level feedback:

  • Consider capturing and at least logging errors from the Expire calls on both viewKey and hllKey so that failures to set TTLs don’t go unnoticed.
  • Because time.Now().Format("20060102") is evaluated inside the collector loop, the same logical event could be bucketed into different dates if it straddles midnight; consider computing the date when the event is enqueued and passing it through the channel instead.
Prompt for AI Agents
Please address the comments from this code review:

## Overall Comments
- Consider capturing and at least logging errors from the `Expire` calls on both `viewKey` and `hllKey` so that failures to set TTLs don’t go unnoticed.
- Because `time.Now().Format("20060102")` is evaluated inside the collector loop, the same logical event could be bucketed into different dates if it straddles midnight; consider computing the date when the event is enqueued and passing it through the channel instead.

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.

Copilot AI left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

Pull request overview

This PR aims to improve request/DAU counting accuracy and safety by deduplicating per-resource daily request counts via Redis HyperLogLog and by cloning request-derived strings before sending them to background collectors.

Changes:

  • Clone IP/rid/version strings before sending them across goroutines to avoid unsafe aliasing with request-scoped buffers.
  • Add a per-resource-per-day HyperLogLog (hll:resource:<rid>:<date>) to only increment the daily ranking once per unique IP.
  • Add expirations for the new per-resource HLL keys (and adjust collector flow accordingly).

Reviewed changes

Copilot reviewed 2 out of 2 changed files in this pull request and generated 3 comments.

File Description
internal/middleware/dau_record.go Clone c.IP() before sending to the DAU collector goroutine.
internal/interfaces/rest/handler/version.go Use per-resource daily HLL to gate ranking increments; clone tuple fields before enqueuing; add expirations for the new HLL keys.

💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

Comment thread internal/middleware/dau_record.go
Comment thread internal/interfaces/rest/handler/version.go
Comment thread internal/interfaces/rest/handler/version.go
@Aliothmoon Aliothmoon merged commit fddac51 into main Apr 1, 2026
6 checks passed
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