Skip to content

[Hotfix] fix data handling when counting view cout on news article#4837

Merged
redmushie merged 5 commits into
ss14Starlight:starlight-devfrom
CringeCursed:newsreaderfix
Jun 20, 2026
Merged

[Hotfix] fix data handling when counting view cout on news article#4837
redmushie merged 5 commits into
ss14Starlight:starlight-devfrom
CringeCursed:newsreaderfix

Conversation

@CringeCursed

Copy link
Copy Markdown
Member

Short description

Why we need to add this

Media (Video/Screenshots)

Checks

  • I do not require assistance to complete the PR.
  • Before posting/requesting review of a PR, I have verified that the changes work.
  • I have added screenshots/videos of the changes, or this PR does not change in-game mechanics.
  • I affirm that my changes are licensed under the MIT License and grant permission for use in this repository under its conditions.

@CringeCursed CringeCursed requested a review from a team June 17, 2026 14:19
@github-actions github-actions Bot added Changes: C# S: Untriaged Status: Indicates an item has not been triaged and doesn't have appropriate labels. S: Needs Review Status: Requires additional reviews before being fully accepted. Not to be replaced by S: Approved. size/S labels Jun 17, 2026
@coderabbitai

coderabbitai Bot commented Jun 17, 2026

Copy link
Copy Markdown
Contributor

Review Change Stack

Warning

Review limit reached

@CringeCursed, we couldn't start this review because you've reached your PR review rate limit.

More reviews will be available in 1 minute and 15 seconds. Learn how PR review limits work.

Your organization has used up its prepaid credits, and credit purchases are no longer available. Enable the review add-on in the billing tab to keep reviews running — you're only billed for reviews past your plan's rate limits ($0.25/file).

⌛ How to resolve this issue?

After more reviews become available, a review can be triggered using the @coderabbitai review command as a PR comment. Alternatively, push new commits to this PR.

To avoid repeated limits, reduce automatic review volume by pausing incremental auto-reviews earlier, using label-based review opt-in, excluding WIP or generated PR titles, or requesting reviews manually when the PR is ready. If your team needs uninterrupted high-volume reviews, an organization admin can enable usage-based credits.

🚦 How do rate limits work?

CodeRabbit enforces per-developer PR review limits for each organization. Most developers receive the normal plan refill rate.

For paid Pro and Pro+ PR reviews, CodeRabbit uses adaptive limits for sustained high-volume activity. When a developer's recent PR review activity reaches the 95th percentile or higher among CodeRabbit users, the refill rate gradually slows as usage increases. The highest same-day bursts are limited more strictly.

Please see our Fair Usage Limits Policy for further information.

ℹ️ Review info
⚙️ Run configuration

Configuration used: Repository UI (base), Organization UI (inherited)

Review profile: CHILL

Plan: Pro

Run ID: bb8debe5-f8fd-4993-af59-8e91d2b5a954

📥 Commits

Reviewing files that changed from the base of the PR and between cbf9f6e and 2770c74.

📒 Files selected for processing (1)
  • Content.Server/MassMedia/Systems/NewsSystem.cs
📝 Walkthrough

Walkthrough

StationNewsReactionsComponent gains a ViewedByArticle dictionary mapping article indices to sets of viewer tuples. NewsSystem adds TryCountCurrentArticleView, TryGetArticleViews, RemoveArticleTracking, and ShiftArticleTracking to deduplicate per-article view counts using station record keys and generalize tracking cleanup on article deletion.

Changes

Per-article view deduplication tracking

Layer / File(s) Summary
ViewedByArticle storage field
Content.Server/MassMedia/Components/StationNewsReactionsComponent.cs
Adds the ViewedByArticle public readonly dictionary to store per-article viewer sets alongside the existing ReactedByArticle dictionary. Clean extension of the existing data model.
View counting and tracking helpers
Content.Server/MassMedia/Systems/NewsSystem.cs
Adds TryCountCurrentArticleView (deduplicates via station record keys), TryGetArticleViews (fetches/creates ViewedByArticle hash sets), RemoveArticleTracking (shifts both reaction and view dictionaries after deletion), and ShiftArticleTracking (index-shifting logic). Excellent work generalizing the tracking removal to handle both reactions and views cohesively.
Wiring into deletion and reader UI
Content.Server/MassMedia/Systems/NewsSystem.cs
OnWriteUiDeleteMessage now calls RemoveArticleTracking instead of the reaction-only removal; UpdateReaderUi now calls TryCountCurrentArticleView instead of directly incrementing the view count. The refactoring maintains all prior behavior while cleanly extending support for view deduplication.

Estimated code review effort

🎯 3 (Moderate) | ⏱️ ~20 minutes

Possibly related PRs

  • ss14Starlight/space-station-14#4822: Directly related — introduces the initial "views count and Like/Dislike" Starlight implementation in NewsSystem and StationNewsReactionsComponent that this PR extends with per-viewer deduplication.

Suggested labels

size/M

Suggested reviewers

  • Rinary1
  • redmushie
🚥 Pre-merge checks | ✅ 7 | ❌ 1

❌ Failed checks (1 warning)

Check name Status Explanation Resolution
Docstring Coverage ⚠️ Warning Docstring coverage is 0.00% which is insufficient. The required threshold is 80.00%. Write docstrings for the functions missing them to satisfy the coverage threshold.
✅ Passed checks (7 passed)
Check name Status Explanation
Title check ✅ Passed The title directly addresses the main change—fixing data handling for view count on news articles—which aligns with the primary modifications to view tracking in NewsSystem.cs and the new ViewedByArticle dictionary.
Description check ✅ Passed While the description lacks technical details about the specific bug and fix, it contains a completed checklist confirming the changes have been tested and are licensed under MIT, which demonstrates engagement with the PR process even if minimal context is provided.
Linked Issues check ✅ Passed Check skipped because no linked issues were found for this pull request.
Out of Scope Changes check ✅ Passed Check skipped because no linked issues were found for this pull request.
No Magic Numbers ✅ Passed All numeric literals in the PR are obvious exceptions (0, 1, -1) used appropriately for initialization, navigation, and array indexing, improving code clarity without creating magic numbers.
No Hardcoded Ecs Parameters ✅ Passed All ECS configuration properly defined in components: ViewedByArticle tracked in StationNewsReactionsComponent, view counting routed through existing component fields and dependencies with no hardc...
Avoid Service Locator ✅ Passed All dependencies in NewsSystem.cs are properly injected via [Dependency] attributes. No service locator patterns like IoCManager.Resolve() detected. Log usage is standard Robust engine logging, not...

✏️ Tip: You can configure your own custom pre-merge checks in the settings.


Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

❤️ Share

Comment @coderabbitai help to get the list of available commands and usage tips.

@coderabbitai coderabbitai 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.

Actionable comments posted: 1

🤖 Prompt for all review comments with AI agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.

Inline comments:
In `@Content.Server/MassMedia/Systems/NewsSystem.cs`:
- Around line 540-551: The ShiftArticleTracking method has a critical bug where
OrderByDescending causes tracking data loss. When iterating in descending order
and shifting indices down (index - 1), the write operation overwrites dictionary
entries that haven't been processed yet. Fix this by changing the sort order
from OrderByDescending to OrderBy (ascending), or by removing the sort entirely.
This ensures entries are processed from lowest to highest index, preventing
overwrites of unprocessed data during the shifting operation.
🪄 Autofix (Beta)

Fix all unresolved CodeRabbit comments on this PR:

  • Push a commit to this branch (recommended)
  • Create a new PR with the fixes

ℹ️ Review info
⚙️ Run configuration

Configuration used: Repository UI (base), Organization UI (inherited)

Review profile: CHILL

Plan: Pro

Run ID: 92e38e8c-2e4e-495d-952c-1810b0760396

📥 Commits

Reviewing files that changed from the base of the PR and between 9b4a301 and 9102915.

📒 Files selected for processing (2)
  • Content.Server/MassMedia/Components/StationNewsReactionsComponent.cs
  • Content.Server/MassMedia/Systems/NewsSystem.cs

Comment thread Content.Server/MassMedia/Systems/NewsSystem.cs Outdated
coderabbitai[bot]
coderabbitai Bot previously approved these changes Jun 17, 2026
Comment thread Content.Server/MassMedia/Systems/NewsSystem.cs Outdated
@starlightgithub starlightgithub Bot added S: Awaiting Changes Status: Changes are required before another review can happen and removed S: Needs Review Status: Requires additional reviews before being fully accepted. Not to be replaced by S: Approved. labels Jun 18, 2026
@github-actions github-actions Bot added the S: Merge Conflict Status: Needs to resolve merge conflicts before it can be accepted label Jun 19, 2026
@github-actions

Copy link
Copy Markdown
Contributor

This pull request has conflicts, please resolve those before we can evaluate the pull request.

@github-actions github-actions Bot removed the S: Merge Conflict Status: Needs to resolve merge conflicts before it can be accepted label Jun 20, 2026
@CringeCursed CringeCursed requested a review from redmushie June 20, 2026 11:11
@github-actions github-actions Bot added S: Needs Review Status: Requires additional reviews before being fully accepted. Not to be replaced by S: Approved. and removed S: Awaiting Changes Status: Changes are required before another review can happen labels Jun 20, 2026
@starlightgithub starlightgithub Bot added S: Approved Status: Reviewed and approved by at least one maintainer or dev; a PR may require another approval. and removed S: Needs Review Status: Requires additional reviews before being fully accepted. Not to be replaced by S: Approved. labels Jun 20, 2026
@redmushie redmushie added this pull request to the merge queue Jun 20, 2026
@redmushie redmushie removed this pull request from the merge queue due to a manual request Jun 20, 2026
@redmushie redmushie added this pull request to the merge queue Jun 20, 2026
Merged via the queue into ss14Starlight:starlight-dev with commit 8960853 Jun 20, 2026
24 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

Changes: C# S: Approved Status: Reviewed and approved by at least one maintainer or dev; a PR may require another approval. S: Untriaged Status: Indicates an item has not been triaged and doesn't have appropriate labels. size/M

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants