Skip to content

Commit 132cc26

Browse files
bewestCopilot
andcommitted
docs: replace V3 'worth verifying' note with verified findings
V3 (POST /api/v3/profile) verified to have request-level dedup but not edit-level dedup — each AAPS edit creates a new profile doc, same architectural symptom as pre-fix V1. Tests in tests/api3.aaps-patterns.test.js in the c-r-m worktree characterize this. Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
1 parent 6d8ffb9 commit 132cc26

1 file changed

Lines changed: 17 additions & 1 deletion

File tree

docs/aaps-profile-sync-impact-analysis-2026-04-20.md

Lines changed: 17 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -293,7 +293,23 @@ A `DataSyncSelectorV1Test` does not currently exist (only V3 has a test). The si
293293

294294
- **Should `PairProfileStore` track `nightscoutId`?** Every other `Pair*` does. Tracking would let AAPS use stable `_id` references and allow the c-r-m server to do `_id`-based dedup rather than `startDate`-based. It would also unblock a future `nsUpdate` path for profiles.
295295
- **The `createdAt % 1000 == 0L` heuristic in `NsIncomingDataProcessor.processProfile:283-295`** ("whole second means edited in NS") is fragile — any AAPS-originated profile whose epoch happens to land on a whole second will be re-imported as if NS-edited. Worth replacing with explicit provenance.
296-
- **V3 path** uses REST POST and `lib/server/profile.js:save()` (which now does `replaceOne` upsert by `_id`), but `createProfileStore` does not include `_id`, so V3 may exhibit the same insert-on-edit behavior via REST. Worth verifying separately.
296+
297+
## V3 path verification
298+
299+
V3 hits `POST /api/v3/profile` (`NightscoutRemoteService.kt:102-103`), which routes to `lib/api3/generic/create/operation.js`. The handler computes an identifier as `uuid.v5("undefined_<doc.date>")` (since profile docs have no `device` or `eventType`) and uses it for dedup via `identifyingFilter`. Verified with three new tests in `tests/api3.aaps-patterns.test.js` under `Profile sync via REST (V3) - AAPS createProfileStore behavior`:
300+
301+
| Scenario | V3 result |
302+
|---|---|
303+
| First POST | 201, one doc inserted |
304+
| Resend identical payload (retry) | **200, deduped in place** (request-level dedup works) |
305+
| Edit profile in AAPS → new `LocalProfileLastChange` → new `date` | **201, new doc inserted** (different identifier) |
306+
307+
So V3 has **request-level dedup but not edit-level dedup**. Each user edit still accumulates a new MongoDB profile document — the same architectural symptom as pre-fix V1.
308+
309+
**Implications:**
310+
- After the c-r-m fix, V1 is now *better* than V3 for AAPS-shaped profile edits: V1 dedups by `startDate` and converges to a single document; V3 still accumulates one document per edit.
311+
- Both paths rely on `ctx.profile.last()` to choose the displayed profile, so the secondary sort key fix (`{startDate: -1, _id: -1}`) helps both.
312+
- A symmetric fix for V3 would extend `calculateIdentifier` to dedup profile docs by `startDate` (or by `(app, startDate)`), or AAPS could be modified to issue `nsUpdate` (PUT/PATCH) instead of `nsAdd` for profile re-saves so the existing identifier is reused.
297313

298314
---
299315

0 commit comments

Comments
 (0)