[PR #6004] [MERGED] feat: utilize database joins across better-auth #6376

Closed
opened 2026-03-13 12:56:33 -05:00 by GiteaMirror · 0 comments
Owner

📋 Pull Request Information

Original PR: https://github.com/better-auth/better-auth/pull/6004
Author: @ping-maxwell
Created: 11/15/2025
Status: Merged
Merged: 11/21/2025
Merged by: @Bekacru

Base: canaryHead: feat/using-joins-across-ba


📝 Commits (10+)

  • 518f825 feat: utilize database joins across better-auth
  • 310cc73 Merge branch 'canary' into feat/using-joins-across-ba
  • 0362a33 fix: session unit tests
  • c232d0e fix: listOrg inference
  • a2038bf fix: type issues
  • ebbdf11 Merge branch 'canary' into feat/using-joins-across-ba
  • 8d8e0f8 Merge branch 'canary' into feat/using-joins-across-ba
  • 46efbc1 Merge branch 'canary' into feat/using-joins-across-ba
  • d65147f Merge branch 'canary' into feat/using-joins-across-ba
  • ddc828a Merge branch 'canary' into feat/using-joins-across-ba

📊 Changes

5 files changed (+154 additions, -213 deletions)

View changed files

📝 packages/better-auth/src/api/routes/session-api.test.ts (+8 -8)
📝 packages/better-auth/src/db/internal-adapter.ts (+44 -81)
📝 packages/better-auth/src/plugins/organization/adapter.ts (+76 -113)
📝 packages/better-auth/src/plugins/organization/organization.test.ts (+20 -8)
📝 packages/better-auth/src/plugins/organization/routes/crud-members.ts (+6 -3)

📄 Description

Summary by cubic

Use database joins across the internal and organization adapters to eliminate N+1 queries and reduce round trips, speeding up session, account, organization, and team reads.

  • Refactors

    • Internal adapter: join user on session lookups (by token and batch tokens), join user on account lookups, and optionally join accounts on findUserByEmail.
    • Organization adapter: join user on member lookups, join invitations/members/teams on findOrganization, join organization on listOrganizations, and join team members/teams on team queries and listTeamsByUser.
    • Tests: select org members by role (not index), add role update checks, and adjust session cookie cache expectations for fewer DB hits (including JWE).
  • Performance

    • Fewer DB calls and less manual stitching across session, account, org, and team flows.
    • Removes multiple N+1 patterns.

Written for commit 9a0266e8ef. Summary will update automatically on new commits.


🔄 This issue represents a GitHub Pull Request. It cannot be merged through Gitea due to API limitations.

## 📋 Pull Request Information **Original PR:** https://github.com/better-auth/better-auth/pull/6004 **Author:** [@ping-maxwell](https://github.com/ping-maxwell) **Created:** 11/15/2025 **Status:** ✅ Merged **Merged:** 11/21/2025 **Merged by:** [@Bekacru](https://github.com/Bekacru) **Base:** `canary` ← **Head:** `feat/using-joins-across-ba` --- ### 📝 Commits (10+) - [`518f825`](https://github.com/better-auth/better-auth/commit/518f8258f98230efa12aa274d6e573dba73d1de3) feat: utilize database joins across better-auth - [`310cc73`](https://github.com/better-auth/better-auth/commit/310cc730a9359f7b87005c2e49f7f2459d8c0e6f) Merge branch 'canary' into feat/using-joins-across-ba - [`0362a33`](https://github.com/better-auth/better-auth/commit/0362a3304eac386dea26e8222af12a97cf8ebb98) fix: session unit tests - [`c232d0e`](https://github.com/better-auth/better-auth/commit/c232d0e106fcf938a4facb9109fd51e80062da47) fix: listOrg inference - [`a2038bf`](https://github.com/better-auth/better-auth/commit/a2038bfe10f54641e5bcdab71317b6587053a428) fix: type issues - [`ebbdf11`](https://github.com/better-auth/better-auth/commit/ebbdf11901ea9d825cacd6d46a67d833495c86da) Merge branch 'canary' into feat/using-joins-across-ba - [`8d8e0f8`](https://github.com/better-auth/better-auth/commit/8d8e0f8341bbf07badb0d019bf1343ef21bd7c84) Merge branch 'canary' into feat/using-joins-across-ba - [`46efbc1`](https://github.com/better-auth/better-auth/commit/46efbc1e2e3fdde0f1b5f08873fa68939fab8c96) Merge branch 'canary' into feat/using-joins-across-ba - [`d65147f`](https://github.com/better-auth/better-auth/commit/d65147f23ff33460da775421cdebe5466323d34d) Merge branch 'canary' into feat/using-joins-across-ba - [`ddc828a`](https://github.com/better-auth/better-auth/commit/ddc828a4ee98ee65125e98d5e62633da34dfc148) Merge branch 'canary' into feat/using-joins-across-ba ### 📊 Changes **5 files changed** (+154 additions, -213 deletions) <details> <summary>View changed files</summary> 📝 `packages/better-auth/src/api/routes/session-api.test.ts` (+8 -8) 📝 `packages/better-auth/src/db/internal-adapter.ts` (+44 -81) 📝 `packages/better-auth/src/plugins/organization/adapter.ts` (+76 -113) 📝 `packages/better-auth/src/plugins/organization/organization.test.ts` (+20 -8) 📝 `packages/better-auth/src/plugins/organization/routes/crud-members.ts` (+6 -3) </details> ### 📄 Description <!-- This is an auto-generated description by cubic. --> ## Summary by cubic Use database joins across the internal and organization adapters to eliminate N+1 queries and reduce round trips, speeding up session, account, organization, and team reads. - **Refactors** - Internal adapter: join user on session lookups (by token and batch tokens), join user on account lookups, and optionally join accounts on findUserByEmail. - Organization adapter: join user on member lookups, join invitations/members/teams on findOrganization, join organization on listOrganizations, and join team members/teams on team queries and listTeamsByUser. - Tests: select org members by role (not index), add role update checks, and adjust session cookie cache expectations for fewer DB hits (including JWE). - **Performance** - Fewer DB calls and less manual stitching across session, account, org, and team flows. - Removes multiple N+1 patterns. <sup>Written for commit 9a0266e8eff35027dee3149d3b8258179b1f807a. Summary will update automatically on new commits.</sup> <!-- End of auto-generated description by cubic. --> --- <sub>🔄 This issue represents a GitHub Pull Request. It cannot be merged through Gitea due to API limitations.</sub>
GiteaMirror added the pull-request label 2026-03-13 12:56:33 -05:00
Sign in to join this conversation.
1 Participants
Notifications
Due Date
No due date set.
Dependencies

No dependencies set.

Reference: github-starred/better-auth#6376