Spaces:
Runtime error
Runtime error
Greg Claude Opus 4.7 (1M context) commited on
Commit ·
bbd61b0
1
Parent(s): dcc7429
docs(backlog): create work backlog with pending optimizations
Browse filesLista de pendientes identificados en sesión 2026-05-31 pero no
abordados en el momento:
- 8 endpoints con N+1 MEDIUM (teacher_*, section_*, sections detalle)
- 2 endpoints con N+1 LOW solo en bulk CSV uploads
- 1 borderline en teacher/students/profile (revisar callers)
- Cleanup de secret RUN_MIGRATIONS en HF Settings
- Validación de cadena Alembic sobre Postgres vacío (deuda)
- Tests integration de los 3 paths del entrypoint
- Cambiar default DEBUG=False en config.py (más seguro)
Formato checklist para tildar a medida que se resuelven.
Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
- docs/backlog.md +60 -0
docs/backlog.md
ADDED
|
@@ -0,0 +1,60 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
# Backlog de trabajo
|
| 2 |
+
|
| 3 |
+
Lista de items identificados pero no abordados todavía. Tickea con `[x]` cuando se resuelven y muévelos a "Hecho" si querés conservar historial, o borralos.
|
| 4 |
+
|
| 5 |
+
## Performance — N+1 queries
|
| 6 |
+
|
| 7 |
+
Patrón uniforme de fix (mismo que usamos en sesión 2026-05-31 para sections/attendances/representative): batch-load-into-dict.
|
| 8 |
+
|
| 9 |
+
**Bad:**
|
| 10 |
+
```python
|
| 11 |
+
items = query.all()
|
| 12 |
+
for item in items:
|
| 13 |
+
related = db.query(Related).filter(Related.id == item.related_id).first()
|
| 14 |
+
```
|
| 15 |
+
|
| 16 |
+
**Good:**
|
| 17 |
+
```python
|
| 18 |
+
items = query.all()
|
| 19 |
+
related_ids = {i.related_id for i in items if i.related_id is not None}
|
| 20 |
+
related_by_id = {r.id: r for r in db.query(Related).filter(Related.id.in_(related_ids)).all()} if related_ids else {}
|
| 21 |
+
for item in items:
|
| 22 |
+
related = related_by_id.get(item.related_id)
|
| 23 |
+
```
|
| 24 |
+
|
| 25 |
+
### MEDIUM (1 + N o 1 + 2-3N)
|
| 26 |
+
|
| 27 |
+
- [ ] **`teacher_sections.py:29-35`** — `GET /api/v1/teacher-sections` — 1 + 2N (carga User + Subject por cada teacher-section). El helper `_enrich` queries adentro. Batch teachers + subjects, pasar como dicts.
|
| 28 |
+
- [ ] **`teacher_subjects.py:29-38`** — `GET /api/v1/teacher-subjects` — 1 + N (Subject por cada). Batch subjects.
|
| 29 |
+
- [ ] **`section_subjects.py:17-37`** — `GET /api/v1/section-subjects` — 1 + N (Subject por cada). Batch subjects.
|
| 30 |
+
- [ ] **`teacher_subjects.py:41-81`** — `PUT /api/v1/teacher-subjects/{teacher_id}` — 1 + 3N. Batch validar subject_ids upfront, pre-fetch conflicting users.
|
| 31 |
+
- [ ] **`section_subjects.py:40-63`** — `PUT /api/v1/section-subjects/{section_id}` — 1 + N. Batch subjects.
|
| 32 |
+
- [ ] **`teacher.py:128-162`** — `GET /api/v1/teacher/subjects` — 1 + 3N (Subject + Section + Enrollment count por assignment). Batch subjects/sections + pre-agregar enrollments con `func.count` + `group_by`.
|
| 33 |
+
- [ ] **`teacher.py:310-346`** — `GET /api/v1/teacher/sections` — 1 + 4N con sub-N+1 anidado (`_section_subjects` adentro del loop). Batch sections, subjects, pre-agregar enrollment counts.
|
| 34 |
+
- [ ] **`teacher.py:693-732`** — `GET /api/v1/teacher/schedule` — 1 + 2N (Section + Subject por schedule). Batch ambos.
|
| 35 |
+
|
| 36 |
+
### LOW (solo en bulk CSV uploads)
|
| 37 |
+
|
| 38 |
+
- [ ] **`enrollments.py:167-238`** — `POST /api/v1/enrollments/bulk` — 1 + 5N en CSVs grandes. Batch upfront: users por email, sections por nombre, enrollments existentes; precomputar capacity checks.
|
| 39 |
+
- [ ] **`users.py:127-224`** — `POST /api/v1/users/bulk` — 1 + 4N en CSVs grandes. Set de emails/card_ids upfront, single batch query para detectar duplicados.
|
| 40 |
+
|
| 41 |
+
### Borderline (revisar si se vuelve N+1 en uso real)
|
| 42 |
+
|
| 43 |
+
- [ ] **`teacher.py:595-644`** — `GET /api/v1/teacher/students/{student_id}/profile` — solo 1 query extra para padre, no es N+1 estrictamente. Solo problemático si se llama en loop desde otro endpoint. Auditar callers antes de tocar.
|
| 44 |
+
|
| 45 |
+
## Otros pendientes operativos
|
| 46 |
+
|
| 47 |
+
- [ ] **Eliminar secret `RUN_MIGRATIONS`** de HF Space Settings si quedó configurado (el código ya no lo lee, pero limpiar evita confusión). UI: https://huggingface.co/spaces/Talosware/talos-access/settings → Variables and secrets.
|
| 48 |
+
- [ ] **Validar cadena Alembic 001→022 sobre Postgres vacío** — en sesión actual usamos `alembic stamp head` para evitar este test. Si en algún momento un dev nuevo arma su entorno con `alembic upgrade head` desde cero, puede fallar por migraciones que se crearon contra MariaDB. Workaround: rebajar a `stamp head` o auditar y reescribir migraciones legacy.
|
| 49 |
+
- [ ] **Crear `backend/tests/test_entrypoint_paths.py`** — integration test que ejerce los 3 paths del entrypoint (UPGRADE/STAMP/INIT) end-to-end. Hubiera atrapado el bug de syntax MySQL en la migración `33cb4ee027ee` antes del bundling en el commit `2b28dbf`. Ver spec `docs/superpowers/specs/2026-05-31-run-migrations-automation-design.md` líneas 129-134.
|
| 50 |
+
- [ ] **Cambiar default `DEBUG` a `False`** en `backend/app/core/config.py:17`. Hoy default es `True` (echo SQL en producción si no se overridea). Cambiar default a `False` y settear `DEBUG=true` solo en `docker-compose.yml` para local. Más seguro como default.
|
| 51 |
+
|
| 52 |
+
## Cómo usar este backlog
|
| 53 |
+
|
| 54 |
+
- Agregar items: cualquier "deuda" detectada en una sesión que no se ataca en el momento debe terminar acá. Si es spec o plan formal, va a `docs/superpowers/`; si es un TODO concreto, va acá.
|
| 55 |
+
- Resolver: tildá `[x]`, podés dejar o mover a sección "Hecho" abajo.
|
| 56 |
+
- Sin owners ni fechas — este es un backlog informal, no un Jira.
|
| 57 |
+
|
| 58 |
+
## Hecho
|
| 59 |
+
|
| 60 |
+
(Mové items aquí cuando se resuelvan, opcional.)
|