mirror of
https://github.com/stack-auth/stack.git
synced 2026-06-13 21:01:21 +08:00
## Summary In preview-mode deployments (`NEXT_PUBLIC_STACK_IS_PREVIEW=true`) the project overview dashboard reported **0 total users, 0 monthly active users, and no live users** on the globe. The internal metrics endpoint reads user/team totals from the ClickHouse `analytics_internal.*` tables and "live users" from recent `$token-refresh` events — but those tables are normally filled by the external-db-sync pipeline, which does not run in preview deployments, so they were empty. This makes the preview/demo dummy-data seeder populate ClickHouse directly: - **`seedDummyAnalyticsMirrorTables`** — mirrors the seeded users / teams / contact channels into `analytics_internal.users` / `teams` / `contact_channels` so the metrics endpoint reports real totals. - **`seedDummyLiveTokenRefreshEvents`** — emits recent `$token-refresh` events across distinct countries so the overview globe shows live users. - **Timestamp clamping** — `bulkRandomTimestampOnDay` and the page-view/click timestamps are clamped so seeded events are never dated in the future (future-dated events permanently matched the unbounded "live users" query). - **`buildTokenRefreshClickhouseRow`** — shared helper for the `$token-refresh` ClickHouse row shape. - **`create-project`** — pre-warms the ClickHouse connection so the seeding inserts don't pay the cold-start cost. - **`projects-metrics`** — types the ClickHouse `.json()` results (fixes a `tsc` error). Also bundles a seeding performance optimization that skips redundant idempotency lookups when seeding a brand-new project. Notes: - Seeded mirror rows use `sync_sequence_id = 0` so that if the external-db-sync pipeline ever does run for the project, any real update supersedes the seeded placeholder under `ReplacingMergeTree` + `FINAL`. - "Live users" naturally decays out of the ~2-minute window a couple of minutes after project creation; preview creates a fresh project per visit, so the initial overview always shows them. ## Test plan - [x] `pnpm --filter @stackframe/backend typecheck` passes - [x] `pnpm --filter @stackframe/backend lint` passes - [x] Created fresh preview projects; overview shows non-zero Total Users / Monthly Active Users - [x] `analytics_internal.users` / `teams` / `contact_channels` populated for the seeded project - [x] Globe shows 8 live users across 8 distinct countries (verified via the metrics 2-minute query) - [x] No future-dated `$token-refresh` events in `analytics_internal.events` <!-- This is an auto-generated comment: release notes by coderabbit.ai --> ## Summary by CodeRabbit * **Refactor** * Faster preview project creation by pre-warming the analytics database and reusing the warmed connection. * Reduced initialization delays and redundant checks when seeding brand-new projects; creation paths now skip needless probes. * More efficient, parallelized seeding of teams/users/events with deterministic handling of token-refresh and session-replay data. * Safer timestamp generation to avoid future-dated events and deferred background processing for long-running tasks like payments. <!-- review_stack_entry_start --> [](https://app.coderabbit.ai/change-stack/hexclave/stack-auth/pull/1471?utm_source=github_walkthrough&utm_medium=github&utm_campaign=change_stack) <!-- review_stack_entry_end --> <!-- end of auto-generated comment: release notes by coderabbit.ai --> --------- Co-authored-by: Konsti Wohlwend <n2d4xc@gmail.com> |
||
|---|---|---|
| .. | ||
| app | ||
| auto-migrations | ||
| lib | ||
| oauth | ||
| private | ||
| route-handlers | ||
| scripts | ||
| utils | ||
| analytics.tsx | ||
| globals.d.ts | ||
| instrumentation.ts | ||
| polyfills.tsx | ||
| prisma-client.tsx | ||
| proxy.tsx | ||
| s3.tsx | ||
| smart-router.tsx | ||
| stack.tsx | ||