Skip to content

feat: show count of active online developers - #123

Open
sadiqk2 wants to merge 1 commit into
dev-null-sh:productionfrom
sadiqk2:feat/online-developers
Open

sadiqk2 wants to merge 1 commit into
dev-null-sh:productionfrom
sadiqk2:feat/online-developers

Conversation

@sadiqk2

@sadiqk2 sadiqk2 commented Oct 15, 2026

Copy link
Copy Markdown
Contributor

Summary

Adds a live indicator showing how many developers are actively online on devnull.

Changes

  1. Activity Tracking:
    • Added last_active_at timestamp column to users table.
    • In HandleInertiaRequests, updates last_active_at for authenticated users when they make a request (throttled to at most once per minute to avoid excessive database writes).
  2. Online Query (OnlineDevelopersQuery):
    • Counts registered developers active within the last 5 minutes.
    • Caches the count for 15 seconds to keep database overhead minimal.
    • Shared via Inertia as onlineDevelopersCount in HandleInertiaRequests.
  3. UI Indicators:
    • Sidebar (AppAside): Displays a live indicator with a pulsing emerald status dot above the footer shortcuts: ● {N} developers online.
    • Navigation (AppNav): Displays the same indicator under the logo on desktop (lg) viewports.
  4. Tests:
    • OnlineDevelopersQueryTest: Asserts active window counting, exclusion of inactive users, and caching.
    • OnlineDevelopersTest: Asserts request activity tracking, 1-minute throttling, and Inertia prop sharing.

@brendt

brendt commented Oct 16, 2026

Copy link
Copy Markdown
Contributor

I'm a bit worried about adding another query for every inertia request. I like the feature though. Any alternative approaches to this that might be less intensive?

@sadiqk2

sadiqk2 commented Oct 17, 2026

Copy link
Copy Markdown
Contributor Author

Thanks for the feedback @brendt! Good call on keeping the main request cycle lightweight.

I've pushed an update addressing this, and here are the approaches:

1. Inertia Deferred Prop (Inertia::defer) + 60s Cache (Implemented)

  • Zero latency on main requests: Wrapped onlineDevelopersCount with Inertia::defer(...) in HandleInertiaRequests, matching how suggestedUsers is handled. The initial Inertia response renders immediately without executing any queries for this count; Inertia fetches it in a separate non-blocking background request.
  • Lightweight Skeleton Fallback: The frontend indicator now uses <Deferred data="onlineDevelopersCount" fallback={<Skeleton className="h-3.5 w-24" />}> in both AppAside and AppNav.
  • Increased Cache TTL: Increased CACHE_TTL_SECONDS from 15s to 60s in OnlineDevelopersQuery, ensuring the database count() query runs at most once a minute globally.
  • Throttled activity writes: Authenticated user last_active_at writes remain throttled to at most once per minute per user (diffInMinutes >= 1).

Alternative Architectural Approaches (if you prefer):

  • Cache-only / Redis Presence (no DB writes or count queries): Instead of storing last_active_at on the users table, we could track active user presence in Redis/Cache (e.g., Redis sets or HyperLogLog with 5-minute expiry), completely bypassing database writes and counts.
  • Scheduled Background Worker: A scheduled task or command running every minute could calculate the count and store it in cache (Cache::forever), making the request lifecycle a fast cache lookup with 0 table queries.

Also resolved the Rector and Pest assertions with Date::setTestNow and arrow functions. Let me know what you think!

@xHeaven

xHeaven commented Oct 18, 2026

Copy link
Copy Markdown
Member

@nunomaduro This PR touches database migrations. Could you take a look?

@sadiqk2
sadiqk2 force-pushed the feat/online-developers branch from a222a67 to 1c5677a Compare October 18, 2026 14:40
@sadiqk2
sadiqk2 force-pushed the feat/online-developers branch from 1c5677a to f1ad58a Compare October 18, 2026 14:59
chrismessina added a commit to chrismessina/dev-null.sh that referenced this pull request Oct 23, 2026
#000 and #000000 are black, and #333333 is gray, but they showed as plain
text because a color needed a letter. Issue numbers never start with a
zero and aren't 6 or 8 digits long, so those count as colors now, while
dev-null-sh#123 and dev-null-sh#333 still stay plain. The pattern also spells its zero-width
characters as escapes instead of the invisible characters themselves.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
chrismessina added a commit to chrismessina/dev-null.sh that referenced this pull request Oct 23, 2026
#000 and #000000 are black, and #333333 is gray, but they showed as plain
text because a color needed a letter. Issue numbers never start with a
zero and aren't 6 or 8 digits long, so those count as colors now, while
dev-null-sh#123 and dev-null-sh#333 still stay plain. The pattern also spells its zero-width
characters as escapes instead of the invisible characters themselves.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
jubianchi added a commit to jubianchi/dev-null.sh that referenced this pull request Nov 18, 2026
A hashtag had to start with a letter, so guilds like #3dprinting or
when a letter follows them.

Bare colors and issue references keep their meaning: numbers alone, as
in dev-null-sh#123, stay an issue reference, and a word that is a hex color
starting with a digit, as in #3d3d3d or #2fa, stays a color and cannot
name a guild. Letter-first hashtags such as #dead keep the behaviour
from dev-null-sh#1630.
jubianchi added a commit to jubianchi/dev-null.sh that referenced this pull request Nov 18, 2026
A hashtag had to start with a letter, so guilds like #3dprinting or
when a letter follows them.

Bare colors and issue references keep their meaning: numbers alone, as
in dev-null-sh#123, stay an issue reference, and a word that is a hex color
starting with a digit, as in #3d3d3d or #2fa, stays a color and cannot
name a guild. Letter-first hashtags such as #dead keep the behaviour
from dev-null-sh#1630.
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.

3 participants