mirror of
https://github.com/stack-auth/stack.git
synced 2026-07-03 21:02:05 +08:00
## Summary The internal `preview/create-project` endpoint was taking ~15s because `seedDummyProject` created its dummy users one at a time through the full `usersCrudHandlers.adminCreate` CRUD pipeline (one DB transaction + config render per user, ~86 users). This reworks the seeding path to use bulk inserts. End-to-end, the endpoint's server-side handler time drops from **~15,100ms → ~1,300ms** (~11× faster). ## Seeding changes (`seed-dummy-data.ts`) - **`seedDummyUsers` — bulk insert.** Build every row (`ProjectUser`, `ContactChannel`, `AuthMethod`, `ProjectUserOAuthAccount`, `OAuthAuthMethod`, default permissions) up front with pre-generated UUIDs, then insert via one `createMany` per table inside a single transaction — replacing ~86 sequential `adminCreate` transactions. Named-user team memberships are bulk-inserted the same way (`TeamMember` + `TeamMemberDirectPermission`). Idempotency is preserved with a single up-front email lookup, so re-runs against an existing project still skip existing users. - **Native `randomUUID`.** The seed paths now use `node:crypto`'s `randomUUID()` instead of stack-shared's `generateUuid()`. The browser-safe polyfill calls `crypto.getRandomValues` ~31× per UUID (once per template char, each with a fresh `Uint8Array(1)`); generating thousands of seed UUIDs made that ~800ms of pure CPU in the activity-event build alone. - **`seedBulkSignupsAndActivity`.** Skip the redundant back-date `UPDATE` for freshly-inserted users (`createMany` already writes correct `createdAt`/`signedUpAt`), and flush ClickHouse events in larger, parallel batches. - **`seedDummyProject`.** Run `seedBulkSignupsAndActivity` concurrently with the lighter remaining steps, and fold `seedDummyTransactions` into the emails/activity/replays `Promise.all`. - Removed the now-unused `syncSeedUserOauthProviders` helper. The bulk path produces the same rows as the CRUD-handler path (verified row-count equality during development). Webhooks / soft-limit checks are intentionally not fired for seed data, consistent with the rest of the seed. ## Also in this PR — preview-mode 404 fix (`preview-project-redirect.tsx`) While testing the above, the dashboard 404'd right after a preview project was created. In preview mode the `/projects` page renders `PreviewProjectRedirect`, which `POST`s `/internal/preview/create-project` and then `router.push()`es to `/projects/<new-id>` — but it never refreshed the client-side owned-projects cache, so the `[projectId]` route's `useAdminApp()` read a stale list, failed to find the just-created project, and called `notFound()`. Fixed by refreshing the owned-projects cache before navigating, matching what the normal create-project flow in `page-client.tsx` already does. (Pre-existing bug, not caused by the seeding change — but it surfaces the seeding path, so it's bundled here.) ## Testing `pnpm typecheck` and `pnpm lint` pass for both backend and dashboard. The preview endpoint was exercised repeatedly during development (HTTP 200, projects created and populated correctly). <!-- This is an auto-generated comment: release notes by coderabbit.ai --> ## Summary by CodeRabbit * **Performance** * Much faster bulk user and event seeding via larger, parallelized batches and optimized backfilling. * **Refactor** * Dummy data seeding redesigned to be idempotent, deterministic, and bulk-oriented; seeding tasks now overlap where safe. * **Bug Fixes** * Preview project flow validates client capabilities and refreshes the local project list to avoid stale navigation. * Auto-login guarded to run only once to prevent duplicate sign-ins. * **UI/UX** * Walkthrough steps and sidebar behavior improved; walkthrough labels and search keywords updated. * **Chore** * CLI identity command now resolves session authentication more reliably. <!-- review_stack_entry_start --> [](https://app.coderabbit.ai/change-stack/hexclave/stack-auth/pull/1437?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 --> |
||
|---|---|---|
| .. | ||
| ai | ||
| bulldozer | ||
| payments | ||
| cache.tsx | ||
| cel-evaluator.ts | ||
| clickhouse-errors.ts | ||
| clickhouse.tsx | ||
| config.tsx | ||
| contact-channel.tsx | ||
| conversation-types.ts | ||
| conversations-api.ts | ||
| conversations.tsx | ||
| dev-perf-stats.tsx | ||
| dev-request-stats.tsx | ||
| development-environment.ts | ||
| email-delivery-stats.tsx | ||
| email-drafts.tsx | ||
| email-queue-step.test.tsx | ||
| email-queue-step.tsx | ||
| email-rendering.test.tsx | ||
| email-rendering.tsx | ||
| email-template-rewrite.ts | ||
| emailable.tsx | ||
| emails-low-level.tsx | ||
| emails.tsx | ||
| end-users.tsx | ||
| events.tsx | ||
| external-db-sync-metadata.ts | ||
| external-db-sync-queue.ts | ||
| external-db-sync.ts | ||
| featurebase.tsx | ||
| images.tsx | ||
| internal-api-keys.tsx | ||
| internal-feedback-emails.tsx | ||
| js-execution.tsx | ||
| local-emulator.test.ts | ||
| local-emulator.ts | ||
| managed-email-domains.tsx | ||
| managed-email-onboarding.tsx | ||
| metrics-activity-split.ts | ||
| notification-categories.ts | ||
| oauth.tsx | ||
| openapi.tsx | ||
| payments.test.tsx | ||
| payments.tsx | ||
| permissions.tsx | ||
| plan-entitlements.test.ts | ||
| plan-entitlements.ts | ||
| preview-mode.ts | ||
| product-versions.tsx | ||
| projects.tsx | ||
| redirect-urls.test.tsx | ||
| redirect-urls.tsx | ||
| request-checks.tsx | ||
| risk-scores.tsx | ||
| seed-dummy-data.test.ts | ||
| seed-dummy-data.ts | ||
| session-replays.tsx | ||
| sign-up-context.ts | ||
| sign-up-heuristics.tsx | ||
| sign-up-rules.ts | ||
| stripe-proxy.tsx | ||
| stripe.tsx | ||
| telegram.tsx | ||
| tenancies.tsx | ||
| tokens.tsx | ||
| turnstile.tsx | ||
| types.tsx | ||
| upstash.tsx | ||
| users.tsx | ||
| webhooks.tsx | ||