feat(sync): paginate Android sync with change tokens
Lint / Lint (push) Successful in 1m8s
Tests / Go backend (push) Failing after 1m23s
Tests / Dashboard checks (push) Failing after 38s
Docker / Docker Build & Push (push) Failing after 6m29s

This commit is contained in:
Gabriel20xx committed 2026-10-20 15:27:53 +00:00
1 parent 0ff94f9b10
commit 97c237be80
76 files changed
+3401 -851

No files matched your search

+11 -11
View File
@@ -4,10 +4,10 @@
- **Path:** /workspace/Personal/Web/Originals/CollabTable
- **Analyzed:** 2026-10-16
- **Commit:** 6aec03f on main
- **Working tree:** clean (no uncommitted changes, no untracked files)
- **Working tree:** contains uncommitted changes from the earlier and current medium passes.
- **Stack:** Go 1.26 (net/http, pgx v5) API server; PostgreSQL; SvelteKit 2 / Svelte 5 static SPA (Vite 8, TanStack Query) embedded in the Go binary; Android client (Kotlin, Room, Retrofit) with offline sync; Docker multi-stage image on `scratch`; GitHub Actions.
- **Updated:** 2026-10-19 — Critical, High and Medium findings handled in the working tree (not committed). A second Medium pass re-checked P-004, which stays open for a pagination contract decision.
- **Scope:** Read all first-party backend code (`backend/*.go`, including tests), `docker/Dockerfile`, `.dockerignore`, `.github/workflows/*`, the frontend data layer, list components, routes and Vite config, the Android API client, preferences and sync repository, and the shared auth, postgres and authclient code that CollabTable calls. Excluded: `node_modules`, `frontend/.svelte-kit`, the Gradle wrapper, lock files (read for versions only), build output, and the rest of `shared/` (node, python and java packages, which CollabTable does not use). Tracked SQLite files were inspected read-only from a copy (schema and row counts only). No tests, builds or linters were run; the analysis is static.
- **Updated:** 2026-10-20 — P-004 now uses bounded keyset pages for collection endpoints and sync; Android follows all sync pages. Database-backed behavior remains unverified locally because no test database is available.
- **Scope:** Read all first-party backend code (`backend/*.go`, including tests), `docker/Dockerfile`, `.dockerignore`, `.github/workflows/*`, the frontend data layer, list components, routes and Vite config, the Android API client, preferences and sync repository, and the shared auth, postgres and authclient code that CollabTable calls. Excluded: `node_modules`, `frontend/.svelte-kit`, the Gradle wrapper, lock files (read for versions only), build output, and the rest of `shared/` (node, python and java packages, which CollabTable does not use). Tracked SQLite files were inspected read-only from a copy (schema and row counts only). Verification limits are recorded in `QUALITY_REPORT.md`.
## Summary
@@ -15,11 +15,11 @@
|---|---:|---:|---:|---:|
| Critical | 0 | 0 | 0 | 0 |
| High | 2 | 1 | 0 | 1 |
| Medium | 5 | 4 | 0 | 1 |
| Medium | 5 | 5 | 0 | 0 |
| Low | 3 | 0 | 0 | 3 |
| Info | 1 | 0 | 0 | 1 |
Two structural costs dominate: the dashboard re-downloads the full database every 5 seconds, and sync writes row by row with several round trips per value inside one long transaction. Missing indexes and pagination will make both worse as data grows.
The dashboard still sends the full dataset after a change, and sync writes rows one at a time inside one transaction. Collection endpoints and sync are now paged, while the updated-at indexes are present. Database runtime and load behavior still need verification on PostgreSQL.
## Issues
@@ -44,12 +44,12 @@ Two structural costs dominate: the dashboard re-downloads the full database ever
- **Recommendation:** Add `CREATE INDEX IF NOT EXISTS` on `updatedat` for `lists`, `items`, `fields` and `item_values` in `initSchema`. Consider `(isdeleted, updatedat)` if soft-delete filtering is common in the same queries.
- **Status:** Fixed 2026-10-19 — `initSchema` creates indexes on `updatedat` for lists, fields, items and item values, so delta queries stop scanning whole tables. The index builds run at startup and briefly block writes on large tables. Files: backend/db.go.
### P-004 · No pagination on list endpoints or the sync response; the first sync returns everything · **Medium** · Open
- **Location:** `backend/data.go:68-204` (`queryLists`, `queryFields`, `queryItems`, `queryValues`, none with LIMIT), `backend/data.go:228-235` (`GET /api/lists`), `backend/sync.go:216-248` (`since` is nil when `lastSync == 0`, so the full table is returned).
- **Description:** Collection endpoints return unbounded arrays. The first sync from any device (`lastSync == 0`) returns every list, field, item and value in the database in one response.
### P-004 · No pagination on list endpoints or the sync response; the first sync returns everything · **Medium** · Fixed
- **Location:** `backend/pagination.go` (bounded keyset pages); `backend/data.go` collection handlers; `backend/sync.go:326-405` (bounded sync response); `CollabTableAndroid/app/src/main/java/com/collabtable/app/data/repository/SyncRepository.kt` (client page loop).
- **Description:** Collection endpoints now return pages of at most 500 rows (default 200), with opaque keyset cursors and `hasMore`. Sync returns at most 500 changes with a server token cursor; Android requests all pages before saving the cursor.
- **Impact:** Response size and server memory grow linearly with total data. Large first syncs risk the 60-second write timeout and slow mobile clients.
- **Recommendation:** Add keyset pagination (a `(updatedat, id)` cursor and a `limit` parameter) to the collection endpoints. For sync, return a `hasMore` flag and a cursor, and let the client loop until it is caught up.
- **Status:** Open 2026-10-19 — Re-checked, unchanged: the collection queries have no LIMIT and `lastSync == 0` still returns every row. Decision needed: the pagination contract (`hasMore` plus a cursor, or keyset on `(updatedat, id)`), the default page size, and the rollout order. CollabTableAndroid has to loop until caught up before the server may page, or existing clients would silently get a truncated sync.
- **Status:** Fixed 2026-10-20 — Collection queries use keyset cursors with a default page of 200 and maximum of 500; sync responses are capped at 500 and include `hasMore` and `nextSyncToken`. Android uploads local changes on the first request, then loops through server pages and stores the final cursor only after completion. Collection GET responses now wrap `items`, `nextCursor` and `hasMore` instead of returning bare arrays. Old sync clients that omit `lastSyncToken` receive 400 and must be upgraded with the backend. PostgreSQL runtime tests are written but skipped locally; see `QUALITY_REPORT.md` Verification. Files: `backend/pagination.go`, `backend/data.go`, `backend/sync.go`, `CollabTableAndroid/app/src/main/java/com/collabtable/app/data/api/CollabTableApi.kt`, `CollabTableAndroid/app/src/main/java/com/collabtable/app/data/repository/SyncRepository.kt`.
### P-005 · Frontend scans full arrays for every row, card and cell on each poll · **Medium** · Fixed
- **Location:** `frontend/src/routes/lists/[id]/+page.svelte:94` (`itemValuesFor(overview.values, item.id)` runs once per visible row and scans every value in the database) and `:98` (`valueFor` per cell); `frontend/src/lib/components/lists/ListCard.svelte:7-8` (each card filters all fields and all items); `frontend/src/lib/features/lists/listHelpers.js:1-15` (linear `filter` and `find` with no index).
@@ -97,8 +97,8 @@ Two structural costs dominate: the dashboard re-downloads the full database ever
- **Recommendation:** None.
## Notes
- Static analysis only. No tests, builds, Docker builds, lint runs or load tests were executed. Estimates come from code reading and should be confirmed with a benchmark on realistic data (for example a few thousand items across several devices).
- Go and frontend verification results are in `QUALITY_REPORT.md`. No load test ran. Estimates should be confirmed with realistic data across several devices.
- AuthGuard's own performance is outside this repository and was not analyzed.
- `shared/` was reviewed selectively: the parts CollabTable imports (`backend/auth`, `authclient`, `authproxy`, `coreconfig`, `postgres`, and the `carriernodeclient` construction). The shared web-ui was searched with grep only. The node, python and java packages were not reviewed.
- The frontend bundle was not measured. The web-ui is imported through its barrel (`import { Pagination } from '@gabriel20xx/web-ui'`), and whether that tree-shakes needs verification with a production build.
- The production frontend build passed after the consumer wired the local design-tokens package and preserved shared-package symlinks; the resulting bundle size was reported by Vite but not benchmarked in a browser.
- No TODO, FIXME or HACK markers were found in `backend/` or `frontend/src/`.