Skip to content

Comments

fix: improve handling of vote counts and minId logic in RankReportHis…#509

Merged
zeng407 merged 1 commit intomasterfrom
develop
Feb 5, 2026
Merged

fix: improve handling of vote counts and minId logic in RankReportHis…#509
zeng407 merged 1 commit intomasterfrom
develop

Conversation

@zeng407
Copy link
Owner

@zeng407 zeng407 commented Feb 5, 2026

…toryBuilder

Copilot AI review requested due to automatic review settings February 5, 2026 07:18
@zeng407 zeng407 merged commit 6ef5ebc into master Feb 5, 2026
9 checks passed
Copy link
Contributor

Copilot AI left a comment

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 improves the vote counting logic in the updateThousandVotesIncremental method of RankReportHistoryBuilder. The changes fix how the system maintains a sliding window of the most recent 1000 votes by correctly calculating how many old votes to remove when new votes are added.

Changes:

  • Improved calculation of votes to remove by introducing $countToRemove based on total vote count instead of simply matching new vote count
  • Enhanced handling of minId initialization for first-time setup (when minId == 0)
  • Updated comments for better code clarity and documentation in Chinese

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

}
// [情況 B] 總數還沒滿 1000,不需要移除舊資料
// 但如果是第一次建立 ($minId == 0),需要設定 minId
elseif ($minId == 0 && $newCount > 0) {
Copy link

Copilot AI Feb 5, 2026

Choose a reason for hiding this comment

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

Inconsistent comparison operators for checking minId. Line 353 uses strict comparison ($minId > 0) while line 379 uses loose equality ($minId == 0). For consistency and to avoid potential type coercion issues, use the same comparison style throughout. Consider using strict equality (===) for the zero check on line 379.

Suggested change
elseif ($minId == 0 && $newCount > 0) {
elseif ($minId === 0 && $newCount > 0) {

Copilot uses AI. Check for mistakes.
Comment on lines +379 to 382
elseif ($minId == 0 && $newCount > 0) {
// 因為 $newVotes 是 orderByDesc,所以最後一筆是 ID 最小的
$newMinId = $newVotes->last()->id;
}
Copy link

Copilot AI Feb 5, 2026

Choose a reason for hiding this comment

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

The comment states this handles the first time case when $minId == 0, but there's a potential edge case. If the cached summary has min_id set to 0 but has non-zero win/lose counts, this could indicate data corruption or an invalid state. The code should either validate this scenario doesn't happen, or handle it more explicitly.

Consider adding a check: if $minId == 0 but $currentTotal > 0, this indicates an inconsistent state that should either be logged or trigger a rebuild from scratch.

Copilot uses AI. Check for mistakes.
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.

1 participant