get-convex / get-convex/better-auth
findIndex in src/client/adapter-utils.ts never matches composite indexes
Nobody has claimed this yet.
- Dominant language
- TypeScript
- Stars
- 764
- Forks
- 125
- PR merge metrics
- No merged PRs in 30d
Description
**Bug: Underscore prefix on range/sort fields breaks composite index lookup**
Lines 190 and 195 prepend `_` to the range and sort field names when building the lookup array:
```js
// L190 (range)
`${indexEqFields.length ? "_" : ""}${boundField}`
// L195 (sort)
`${indexEqFields.length || boundField ? "_" : ""}${sortField}`
```
This produces `["organizationId", "_expiresAt"]`, which is then compared field-by-field against the index definition `["organizationId", "expiresAt"]` at L211:
```js
indexFields.every((field, idx) => field === fields[idx])
```
`"_expiresAt" !== "expiresAt"` — the index is never found, falling back to a full table scan.
**Why it wasn't caught:** Auto-generated Better Auth indexes are single-field (`indexEqFields.length === 0`), so no underscore is added. The bug only surfaces with custom composite indexes (2+ fields).
**Fix — remove the underscore prefixing (L190, L195):**
```diff
- .concat(boundField && boundField !== "createdAt"
- ? `${indexEqFields.length ? "_" : ""}${boundField}`
+ .concat(boundField && boundField !== "createdAt"
+ ? boundField
: "")
- .concat(sortField && sortField !== "createdAt" && boundField !== sortField
- ? `${indexEqFields.length || boundField ? "_" : ""}${sortField}`
+ .concat(sortField && sortField !== "createdAt" && boundField !== sortField
+ ? sortField
: "")
```
Contributor guide
First steps
- Read the whole issue, then the project's contributing guide.
- Comment on the issue to say you are picking it up — it saves two people doing the same work.
- Fork the repository and make your change on a branch.
- Open a pull request that references the issue number.
Research direction
Open src/client/adapter-utils.ts and inspect the lookup-array construction around lines 190 and 195, then compare it with the field-by-field match at line 211. Remove the underscore prefixes from range and sort fields, and verify that a custom composite index is selected instead of falling back to a full table scan.
Written by the indexing model from the issue text.
Assessment
- Tech stack
- typescript
- Domain
- databases
- Issue type
- Bug
- Difficulty
- 1/5
- Estimated time
- Under an hour
- Activity status
- Stale
- Clarity
- Clearly specified
- Newbie friendliness
- 70/100