feat(api): auto-trigger album suggestion runs after new imports #1270

Merged
chris merged 1 commit from feature/album-suggestion-auto-trigger into main 2026-10-16 22:28:14 +02:00
Owner

Summary\n- New AlbumSuggestionAutoTriggerScheduler: every 5 min (configurable) it starts an album-suggestion run with trigger_type='import_completed' for every owner who has media newer than their latest run, no active run, and whose last run is outside a 10-min debounce window.\n- Before this, runs were only ever created by the manual button (POST /api/album-suggestions/runs) — users who never clicked "generate" never received suggestions for newly imported photos. The import_completed value already existed in the V057 check constraint but nothing ever passed it.\n- Run creation goes exclusively through AlbumSuggestionWorkflowService.generate (the controller's path), so the active-run guard, the partial unique index race protection, and the async executor are shared, not duplicated.\n- One SQL query per tick (no N+1), restricted to each user's first media_owner_profiles row to match ownerForUser owner resolution. The scheduled method never throws: per-tick and per-owner guards log and skip.\n\n## Configuration (defaults in code; env override via relaxed binding)\n- memories.album-suggestions.auto-trigger-enabled (default true; false short-circuits before any DB access)\n- memories.album-suggestions.auto-trigger-interval (default 300000 ms)\n- memories.album-suggestions.auto-trigger-debounce-minutes (default 10)\n\n## Validation\n- rtk ./gradlew :apps:api:test --tests '*AlbumSuggestion*' --tests '*AutoTrigger*' → BUILD SUCCESSFUL, 87 tests, 0 failures (7 new scheduler tests with Clock.fixed: new-media→run created (incl. no-prior-run case), active queued/running run→no second run, debounce window→no run, disabled→no run, no-newer-media→no run, no-media owner→no run).\n\n## Notes\n- No existing file was modified — only the new scheduler + its test.\n- Pairs with the window-ordering fix (separate PR): auto-trigger alone would still produce runs whose candidate windows skip recent media while that fix is unmerged.

## Summary\n- New `AlbumSuggestionAutoTriggerScheduler`: every 5 min (configurable) it starts an album-suggestion run with `trigger_type='import_completed'` for every owner who has media newer than their latest run, no active run, and whose last run is outside a 10-min debounce window.\n- Before this, runs were only ever created by the manual button (`POST /api/album-suggestions/runs`) — users who never clicked "generate" never received suggestions for newly imported photos. The `import_completed` value already existed in the V057 check constraint but nothing ever passed it.\n- Run creation goes exclusively through `AlbumSuggestionWorkflowService.generate` (the controller's path), so the active-run guard, the partial unique index race protection, and the async executor are shared, not duplicated.\n- One SQL query per tick (no N+1), restricted to each user's first `media_owner_profiles` row to match `ownerForUser` owner resolution. The scheduled method never throws: per-tick and per-owner guards log and skip.\n\n## Configuration (defaults in code; env override via relaxed binding)\n- `memories.album-suggestions.auto-trigger-enabled` (default `true`; `false` short-circuits before any DB access)\n- `memories.album-suggestions.auto-trigger-interval` (default `300000` ms)\n- `memories.album-suggestions.auto-trigger-debounce-minutes` (default `10`)\n\n## Validation\n- `rtk ./gradlew :apps:api:test --tests '*AlbumSuggestion*' --tests '*AutoTrigger*'` → BUILD SUCCESSFUL, 87 tests, 0 failures (7 new scheduler tests with `Clock.fixed`: new-media→run created (incl. no-prior-run case), active queued/running run→no second run, debounce window→no run, disabled→no run, no-newer-media→no run, no-media owner→no run).\n\n## Notes\n- No existing file was modified — only the new scheduler + its test.\n- Pairs with the window-ordering fix (separate PR): auto-trigger alone would still produce runs whose candidate windows skip recent media while that fix is unmerged.
feat(api): auto-trigger album suggestion runs after new imports
All checks were successful
Wiki Sync / Sync wiki from docs (push) Has been skipped
Build and Deploy / Detect changed services and test scopes (push) Successful in 3s
Build and Deploy / Smoke API and media worker (push) Has been skipped
Build and Deploy / Smoke web (push) Has been skipped
Build and Deploy / Smoke ML worker (push) Has been skipped
Build and Deploy / Smoke people worker (push) Has been skipped
Build and Deploy / Build postgres image (push) Has been skipped
Build and Deploy / Build Android CI image (push) Has been skipped
Build and Deploy / Build plants worker image (push) Has been skipped
Build and Deploy / Build converter worker image (push) Has been skipped
Build and Deploy / Android unit tests and debug APK (push) Has been skipped
Build and Deploy / Deploy postgres (push) Has been skipped
Build and Deploy / Build API image (push) Has been skipped
Build and Deploy / Build media worker image (push) Has been skipped
Build and Deploy / Build ML worker image (push) Has been skipped
Build and Deploy / Build people worker image (push) Has been skipped
Build and Deploy / Build web image (push) Has been skipped
Build and Deploy / Deploy API (push) Has been skipped
Build and Deploy / Deploy web (push) Has been skipped
Build and Deploy / Deploy media worker (push) Has been skipped
Build and Deploy / Deploy ML worker (push) Has been skipped
Build and Deploy / Deploy plants worker (push) Has been skipped
Build and Deploy / Deploy people worker (push) Has been skipped
Build and Deploy / Deploy converter worker (push) Has been skipped
Build and Deploy / Clean Docker build artifacts (push) Has been skipped
Build and Deploy / Run scoped PR tests (push) Successful in 11m30s
a7368f240d
chris merged commit 29a98e8ef4 into main 2026-10-16 22:28:14 +02:00
Sign in to join this conversation.
No reviewers
No labels
No milestone
No project
No assignees
1 participant
Notifications
Due date
The due date is invalid or out of range. Please use the format "yyyy-mm-dd".

No due date set.

Dependencies

No dependencies set

Reference
chris/memories!1270
No description provided.