perf: make getRelations() pagination consistent and efficient

**Problem**: Pagination behavior was inconsistent across different query patterns:
- getRelations({ from: id, limit: 10 }) fetched ALL relationships then sliced
- getRelations({ limit: 10 }) paginated at storage layer
- storage.getVerbs() offset parameter wasn't being passed to adapters

**Root Cause**:
1. getRelations() used different code paths for from/to vs no-filter queries
2. storage.getVerbs() called getVerbsWithPagination without offset
3. Then tried to slice results, which failed for paginated queries

**Solution**:
- Unified getRelations() to ALWAYS use storage.getVerbs() with pagination
- Fixed storage.getVerbs() to convert offset to cursor for adapters
- All query patterns now paginate efficiently at storage layer
- Eliminated inefficient "fetch all then slice" pattern

**Performance Impact**:
- Before: getRelations({ from: entityId, limit: 10 }) on entity with 1000 relationships = 1000 fetched
- After: Only 10 fetched 
- All tests passing (14/14)

**Breaking**: None - fully backward compatible
This commit is contained in:
David Snelling 2025-10-21 13:28:38 -07:00
parent 8d217f3b84
commit 54d819cfcf
3 changed files with 39 additions and 46 deletions

View file

@ -11,6 +11,9 @@ All notable changes to this project will be documented in this file. See [standa
- Fixed critical bug where `brain.getRelations()` returned `[]` instead of all relationships
- Added support for retrieving all relationships with pagination (default limit: 100)
- Added string ID shorthand syntax: `brain.getRelations(entityId)` as alias for `brain.getRelations({ from: entityId })`
- **Performance**: Made pagination consistent - now ALL query patterns paginate at storage layer
- **Efficiency**: `getRelations({ from: id, limit: 10 })` now fetches only 10 instead of fetching ALL then slicing
- Fixed storage.getVerbs() offset handling - now properly converts offset to cursor for adapters
- Production safety: Warns when fetching >10k relationships without filters
- Fixed broken method calls in improvedNeuralAPI.ts (replaced non-existent `getVerbsForNoun` with `getRelations`)
- Fixed property access bugs: `verb.target``verb.to`, `verb.verb``verb.type`