Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Raw SQL query for fetching users #381

Merged
merged 9 commits into from
Dec 27, 2024
Merged

Raw SQL query for fetching users #381

merged 9 commits into from
Dec 27, 2024

Conversation

N2D4
Copy link
Contributor

@N2D4 N2D4 commented Dec 27, 2024


Important

Introduces raw SQL queries for efficient user data fetching, optimizing backend query execution in crud.tsx and prisma-client.tsx.

  • Behavior:
    • Introduces getUserQuery in crud.tsx for raw SQL user fetching.
    • Updates getUser to use rawQuery for optimized data retrieval.
    • Adds rawQueryAll in prisma-client.tsx for batch query execution.
  • Functions:
    • Modifies getUserLastActiveAtMillis to include projectId parameter.
    • Refactors getUsersLastActiveAtMillis to use raw SQL for efficiency.
  • Misc:
    • Adds isNotNull utility function in objects.tsx.
    • Updates ESLint rules in defaults.js to include TemplateLiteral * in ignored nodes.

This description was created by Ellipsis for 1a0afff. It will automatically update as commits are pushed.

Copy link

vercel bot commented Dec 27, 2024

The latest updates on your projects. Learn more about Vercel for Git ↗︎

Name Status Preview Comments Updated (UTC)
stack-backend ✅ Ready (Inspect) Visit Preview 💬 Add feedback Dec 27, 2024 7:17pm
stack-dashboard ✅ Ready (Inspect) Visit Preview 💬 Add feedback Dec 27, 2024 7:17pm
stack-demo ✅ Ready (Inspect) Visit Preview 💬 Add feedback Dec 27, 2024 7:17pm

@N2D4
Copy link
Contributor Author

N2D4 commented Dec 27, 2024

@ellipsis-dev wdyt

Copy link

@ellipsis-dev ellipsis-dev bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

👍 Looks good to me! Reviewed everything up to b06fabf in 1 minute and 13 seconds

More details
  • Looked at 688 lines of code in 10 files
  • Skipped 0 files when reviewing.
  • Skipped posting 4 drafted comments based on config settings.
1. apps/backend/src/prisma-client.tsx:74
  • Draft comment:
    Consider checking if row_to_json is necessary here, as the data might already be in JSON format. This could potentially simplify the query.
  • Reason this comment was not posted:
    Confidence changes required: 30%
    The use of Prisma.sql and Prisma.raw in the rawQueryArray function is correct, but the use of row_to_json might not be necessary if the data is already in JSON format. However, this is not a critical issue.
2. apps/backend/src/app/api/v1/users/crud.tsx:238
  • Draft comment:
    Consider adding additional error handling or validation to ensure that the query results are as expected, especially when dealing with complex JSON structures.
  • Reason this comment was not posted:
    Confidence changes required: 40%
    The getUserQuery function constructs a raw SQL query using Prisma's SQL template literals. The use of jsonb_build_object and to_jsonb is appropriate for constructing JSON objects from SQL query results. However, the function could benefit from additional error handling or validation to ensure that the query results are as expected.
3. apps/backend/src/app/api/v1/users/crud.tsx:209
  • Draft comment:
    Using a fallback value of 0 might not be appropriate. Consider using a more meaningful default value or handling the case where no events are found more explicitly.
  • Reason this comment was not posted:
    Confidence changes required: 50%
    The getUserLastActiveAtMillis function uses a fallback value of 0, which might not be appropriate for all use cases. It would be better to use a more meaningful default value or handle the case where no events are found more explicitly.
4. apps/backend/src/prisma-client.tsx:56
  • Draft comment:
    Consider adding additional type safety checks to ensure that all queries are valid before execution. This can help prevent runtime errors.
  • Reason this comment was not posted:
    Confidence changes required: 30%
    The rawQueryAll function filters out undefined queries using isNotNull, which is a good practice. However, the function could benefit from additional type safety checks to ensure that all queries are valid before execution.

Workflow ID: wflow_EYa54591KLvRVWFZ


You can customize Ellipsis with 👍 / 👎 feedback, review rules, user-specific overrides, quiet mode, and more.

isAdminKeyValid: projectId && superSecretAdminKey && requestType === "admin" ? checkApiKeySetQuery(projectId, { superSecretAdminKey }) : undefined,
};
const queriesResults = await rawQueryAll(bundledQueries);
console.log("AAAAAAAAA", queriesResults, bundledQueries);
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Remove the console.log statement to avoid unnecessary logging in production.

@N2D4 N2D4 merged commit 8ce7c9f into dev Dec 27, 2024
14 checks passed
@N2D4 N2D4 deleted the raw-user-query branch December 27, 2024 19:31
jshimko added a commit to jshimko/stack that referenced this pull request Dec 28, 2024
* dev: (138 commits)
  Raw project query (stack-auth#382)
  Require pagination cursor to be UUID
  Fix unit tests
  Fix users query
  Log error when selected team member has no team
  chore: update package versions
  Raw SQL query for fetching users (stack-auth#381)
  Better 429 request logging
  Fix STACK-SERVER-NH
  Only fetch keys that are required for the access type
  Improved OTel spans
  Better traceSpan signature
  Even more OTel spans
  Add display name to span attributes
  More OTel spans
  Update backend TypeScript target
  chore: update package versions
  removed GET team transaction
  fixed smtp config bug
  Insert final newline on file save
  ...

# Conflicts:
#	.github/workflows/docker-build.yaml
#	apps/backend/package.json
#	apps/backend/prisma/seed.ts
#	apps/backend/sentry.client.config.ts
#	apps/backend/src/polyfills.tsx
#	apps/dashboard/sentry.client.config.ts
#	apps/dashboard/src/app/(main)/(protected)/(outside-dashboard)/projects/page-client.tsx
#	apps/dashboard/src/app/(main)/(protected)/projects/[projectId]/auth-methods/providers.tsx
#	apps/dashboard/src/components/data-table/user-table.tsx
#	apps/dashboard/src/components/version-alerter.tsx
#	apps/dashboard/src/polyfills.tsx
#	examples/cjs-test/package.json
#	examples/demo/src/app/page-client.tsx
#	examples/middleware/package.json
#	examples/partial-prerendering/package.json
#	package.json
#	packages/stack/package.json
#	packages/stack/src/generated/quetzal-translations.ts
#	packages/stack/src/lib/stack-app.ts
#	pnpm-lock.yaml
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.

1 participant