Skip to content

feat: add registered user stats to ActivityStats via pseudo_user - #19

Draft
Amund-Fremming with Copilot wants to merge 1 commit into
mainfrom
copilot/oppdater-counter-brukere
Draft

feat: add registered user stats to ActivityStats via pseudo_user#19
Amund-Fremming with Copilot wants to merge 1 commit into
mainfrom
copilot/oppdater-counter-brukere

Conversation

Copilot AI commented May 1, 2026

Copy link
Copy Markdown
Contributor

The /activity-stats endpoint had no way to count newly registered users per day/week/month — only active users. Counting directly from base_user alongside pseudo_user active-user stats would cause double-counting for registered users.

Changes

  • models/user.rs — New RegisteredUserStats struct (todays_registered, this_week_registered, this_month_registered); added registered: RegisteredUserStats field to ActivityStats
  • db/user.rs — New concurrent registered_fut query using pseudo_user JOIN base_user filtered by base_user.created_at; result joined into the existing tokio::join! block
  • .sqlx/ — Added offline query cache file for the new query

How double-counting is avoided

Each registered user has exactly one pseudo_user row (with base_user_id set). By driving the count from pseudo_user side via JOIN, every registered user appears exactly once regardless of what else queries base_user:

SELECT
    COUNT(*) FILTER (WHERE b.created_at >= date_trunc('month', CURRENT_DATE)) AS "this_month_registered!",
    COUNT(*) FILTER (WHERE b.created_at >= date_trunc('week',  CURRENT_DATE)) AS "this_week_registered!",
    COUNT(*) FILTER (WHERE b.created_at >= CURRENT_DATE)                      AS "todays_registered!"
FROM pseudo_user p
JOIN base_user b ON b.id = p.base_user_id

The existing RecentUserStats (active users by last_active) is unchanged — it already only touches pseudo_user.

…ser JOIN base_user

Agent-Logs-Url: https://github.com/Amund-Fremming/tero.platform/sessions/b2a8084d-3956-446a-a5fe-964cf2e797e6

Co-authored-by: Amund-Fremming <114174150+Amund-Fremming@users.noreply.github.com>
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