# C2: DrizzleChatRepo.findRows - Closeout Report **File:** `src/db/repositories/drizzle/DrizzleChatRepo.ts` **Method:** `findRows()` **Status:** Fixed in `backend@8835068` / v2.9.35. --- ## What Was Finished The earlier C2 fix moved the hot participant/archive/unread predicates into SQL, but this report correctly identified that edge paths could still fetch too much data. Commit `8835068` closes those remaining gaps: | Gap from the partial report | Final behavior | |---|---| | Empty `findRows({})` fetched the whole chat table | All chat row reads now go through a bounded query builder with a 1000-row max cap | | `findOne({})` could fetch many rows before returning one | `findOne()` now uses `LIMIT 1`; id-only queries use the existing `findById()` fast path | | `findForUser()` applied `skip`/`limit` after fetching all matching rows | SQL-pushable predicates now use DB-side `offset`/`limit` | | Search/fallback predicates still used in-memory matching | Fallback matching remains for unsupported predicates, but only after a bounded 1000-row scan | | Chat `type` was left as a fallback predicate | `type` is now pushed to SQL for `direct`, `group`, and `support` | | `settings.isArchived` had no matching B-tree index in the current schema/migrations | Added schema index and migration `0026_chat_settings_archived_idx.sql` for `chats_settings_is_archived_idx` | ## Verification - `npm run typecheck` - passed. - `npm test -- --runTestsByPath __tests__/drizzle-chat-repo.test.ts __tests__/db-audit-high-indexes.test.ts --runInBand` - passed, 2 suites / 9 tests. - `scripts/smoke/db-audit-service-regressions.sh` - passed, 18 suites / 73 tests. ## Remaining Long-Term Schema Work The C2 unbounded-fetch and pagination issue is closed. The larger chat storage design remains a separate schema project: moving `messages`, `participants`, and `unreadCounts` out of JSONB arrays into relational tables would enable exact indexed deep search, precise fallback pagination, and targeted message updates without rewriting large JSON blobs.