Skip to content

feat: show the total stars a user received on their profile - #278

Closed
silviooosilva wants to merge 20 commits into
dev-null-sh:productionfrom
silviooosilva:feat/profile-stars-total
Closed

silviooosilva wants to merge 20 commits into
dev-null-sh:productionfrom
silviooosilva:feat/profile-stars-total

Conversation

@silviooosilva

@silviooosilva silviooosilva commented Oct 16, 2026 •

Copy link
Copy Markdown

Closes #434

Summary

Shows the total stars a user's commits and replies received from other developers in the profile stats row, next to commits, following and followers.

  • It reads "1 star" or "N stars", and totals past a thousand are shortened with the shared formatCount from feat: short numbers where needed #410, like the sidebar and star buttons: 1.3k, 12.3k, 1.2m, 5b.
  • It updates as soon as someone stars or unstars one of the user's commits on the page, without a reload, the same way the pastéis received count does.

Why

Stars are the engagement action on /dev/null, but today they only show up per commit. The total gives a quick sense of how a developer's commits land with others, and the achievements already count it for XP and the Superstar badge without ever showing the number itself.

How it works

  • UserStarsCountQuery counts the stars on the user's commits that the viewer can see, from other developers only. Guests count approved commits only, and deleted commits are left out.
  • It is now the one place this number is counted. UserAchievementsQuery uses it for stars received, and UserController@show computes it once per request and shares it between the starsCount prop and the achievements, the same way it already shares the streaks. A test asserts the count query runs once.
  • starsCount is a lazy prop, so reloading the commit feed doesn't recompute it, and it stays out of loadCounts, which runs for the sidebar on every request.
  • Starring and unstarring now also return author: { id, stars_received }. The stars_received field is registered in commit-state.ts, so the profile's shared state picks up the new total like it does for pasteis_received.
  • The total is shown with formatCount from resources/js/lib/numbers.ts (feat: short numbers where needed #410), so it reads the same as the other short counts. Singular and plural follow the exact count.
  • The stats row now wraps (flex-wrap) instead of overflowing. With four stats it no longer fits on one line below about 380px, and on 320px and 360px screens the page used to scroll sideways.
  • PRODUCT.md describes the new count.

Not in this PR

  • The hover card, the public API, the link preview image and the profile's structured data still show only commits and followers. Adding stars there changes public output, so it is better as a follow-up if wanted.
  • The other stats (commits, following, followers) are still shown in full, as today.
  • formatCount rounds, so 999,999 reads 1m. Truncating instead (999.9k) would keep a count from reading higher than it is; that belongs in formatCount itself, for every count at once, so it is left for a separate PR.
  • The achievements shelf still updates on the next page load, not live, as before.

Screenshots

Profile

Light Dark
Profile on desktop, light Profile on desktop, dark
Mobile, light Mobile, dark
Profile on mobile, light Profile on mobile, dark

Live update

Starring a commit on the profile takes the total from 13 to 14 with no reload and no layout shift.

Before After starring
Profile with 13 stars before starring Profile with 14 stars after starring

Singular and plural

1 star 13 stars
Stats row with 1 star Stats row with 13 stars

Large totals

Rendered by the real page, with starsCount swapped in the browser instead of creating millions of stars in the database.

Total Shown
999 999 stars
1,000 1000 stars
1,250 1.3k stars
1,999 2k stars
12,345 12.3k stars
999,999 1m stars
1,234,567 1.2m stars
5,000,000,000 5b stars

Narrow screens

A wide total like 999.9k wraps to its own line instead of pushing the page sideways.

390px 360px 320px
Stats row at 390px Stats row at 360px Stats row at 320px

Tests

  • UserStarsCountQueryTest: replies, visibility per viewer, deleted commits, self-stars.
  • CommitStarControllerTest: starring returns the author's new total; the existing exact-JSON assertions in CommitStarCountControllerTest and RateLimitTest include the new author field.
  • UserControllerTest: starsCount for signed-in users and guests, not computed when only commits reloads, and counted once for the stats and the achievements.

Verification

  • Pest with --coverage --exactly=100.0 (all 2,551 tests), the JS unit tests, test:types, Pint, Rector and bun run test:lint pass locally.
  • In Chromium: 1440×900, 1366×650, 390×844, 360×740 and 320×568, in light and dark. No horizontal overflow, and no layout shift on load or when starring and unstarring.
  • Compared with production at the same sizes: the stats row keeps its height, and only wraps to a second line on narrow phones.

@silviooosilva
silviooosilva force-pushed the feat/profile-stars-total branch from ec1626b to 9f32589 Compare October 16, 2026 17:24
Copilot AI balanced review requested due to automatic review settings October 18, 2026 20:35

Copilot AI 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.

🟡 Changes recommended

Profile totals can reset after tab navigation and remain stale after deleting or restoring starred commits.

2 open issues
What changed in this PR

Adds received-star totals to profiles, sharing the visibility-aware count with achievements and updating it after star actions.

Changes:

  • Centralizes star counting and reuses it across profile responses.
  • Adds formatted totals, live updates, and wrapping profile stats.
  • Documents the feature and expands backend coverage.
File Description
tests/​Unit/​Queries/​UserStarsCountQueryTest.php Tests counting, visibility, deletions, and self-star exclusion.
tests/​Feature/​RateLimitTest.php Updates expected star responses.
tests/​Feature/​Controllers/​UserControllerTest.php Tests profile totals and query reuse.
tests/​Feature/​Controllers/​CommitStarCountControllerTest.php Updates star response assertions.
tests/​Feature/​Controllers/​CommitStarControllerTest.php Tests author totals in responses.
resources/​js/​pages/​user/​show.tsx Displays formatted totals and wraps stats.
resources/​js/​lib/​commit-state.ts Registers shared received-star state.
PRODUCT.md Documents profile star totals.
app/​Queries/​UserStarsCountQuery.php Centralizes visibility-aware counting.
app/​Queries/​UserAchievementsQuery.php Reuses the shared count.
app/​Http/​Controllers/​UserController.php Exposes a lazily computed profile total.
app/​Http/​Controllers/​CommitStarController.php Returns author totals after star actions.

Review effort: Balanced

Comment thread app/Http/Controllers/UserController.php Resolved
Comment thread resources/js/pages/user/show.tsx Resolved
Copilot AI balanced review requested due to automatic review settings October 18, 2026 20:52

Copilot AI 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.

🔵 Needs a closer look

Out-of-order star responses can overwrite a newer profile total with an older count.

No open issues 🎉

1 previously missed issue

In code that hasn't changed since last review

Medium severity Concurrent commit stars can overwrite the profile total out of order

resources/​js/​lib/​commit-state.ts:9

Concurrent stars on two different commits by the same author can leave the profile total incorrect. createCommitStarMutations guards requests per commit, but collect and refreshSharedState apply this author-wide total unconditionally. If responses containing totals 14 and 15 arrive in reverse order, the profile ends at 14 even though both stars succeeded. Profile tab reloads omit starsCount, so switching tabs does not correct it. Serialize star mutations per author, or return and check an author-level revision before applying totals. Add a regression test that delivers the responses in reverse order.

2 resolved since last review

Review effort: Balanced

Copilot AI balanced review requested due to automatic review settings October 18, 2026 21:55

Copilot AI 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.

🟡 Changes recommended

Polling and mutation updates can use different baselines, producing incorrect or negative profile star totals.

1 open issue

Review effort: Balanced

Comment thread resources/js/lib/author-stars.ts Resolved
Copilot AI balanced review requested due to automatic review settings October 18, 2026 22:10

Copilot AI 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.

🟢 Approval recommended

No blocking defects remain in the reviewed counting, live-update, or profile integration changes.

No open issues 🎉

1 resolved since last review

Review effort: Balanced

Copilot AI balanced review requested due to automatic review settings October 19, 2026 05:25

Copilot AI 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.

🟢 Approval recommended

Static review identified no blocking defects in counting, visibility filtering, or live-update behavior.

No open issues 🎉

Review effort: Balanced

@nunomaduro

Copy link
Copy Markdown
Member

hey, thanks a lot for this contribution

i'm going to hold it for now, though.. i'm not really planning on showing the number of GitHub stars a user has

thank you for taking the time 🤌🏻

@nunomaduro nunomaduro closed this Oct 19, 2026
@silviooosilva
silviooosilva deleted the feat/profile-stars-total branch October 19, 2026 19:50
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.

Show the total stars a user received on their profile

3 participants