Codebase hardening: 102 fixes across 35+ files
Deep audit identified 106 findings; 102 fixed, 4 deferred. Covers 8 areas: - Settings & deploy: env-gated DEBUG/SECRET_KEY, HTTPS headers, gunicorn, celery worker - Auth (registered_user): password write_only, request.data fixes, transaction safety, proper HTTP status codes - Workout app: IDOR protection, get_object_or_404, prefetch_related N+1 fixes, transaction.atomic - Video/scripts: path traversal sanitization, HLS trigger guard, auth on cache wipe - Models (exercise/equipment/muscle/superset): null-safe __str__, stable IDs, prefetch support - Generator views: helper for registered_user lookup, logger.exception, bulk_update, transaction wrapping - Generator core (rules/selector/generator): push-pull ratio, type affinity normalization, modality checks, side-pair exact match, word-boundary regex, equipment cache clearing - Generator services (plan_builder/analyzer/normalizer): transaction.atomic, muscle cache, bulk_update, glutes classification fix Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
This commit is contained in:
@@ -30,10 +30,14 @@ def create_all_exercise_list_for_workout(workout):
|
||||
data["audio_queues"] = audio_queues
|
||||
all_superset_exercise.append(data)
|
||||
|
||||
supersets = Superset.objects.filter(workout=workout).order_by('order')
|
||||
# Fix #17: N+1 - add prefetch_related to avoid per-superset queries
|
||||
supersets = Superset.objects.filter(workout=workout).order_by('order').prefetch_related(
|
||||
'supersetexercise_set__exercise'
|
||||
)
|
||||
order = 2
|
||||
for superset_count, superset in enumerate(supersets):
|
||||
supersetExercises = SupersetExercise.objects.filter(superset=superset).order_by('order')
|
||||
# Use prefetched data instead of re-querying (N+1 fix)
|
||||
supersetExercises = sorted(superset.supersetexercise_set.all(), key=lambda se: se.order)
|
||||
for x in range(superset.rounds):
|
||||
for exercise_idx, exercise in enumerate(supersetExercises):
|
||||
exercise.order = order
|
||||
@@ -68,7 +72,9 @@ def create_all_exercise_list_for_workout(workout):
|
||||
|
||||
elif len(supersets) > superset_count+1:
|
||||
next_superset = supersets[superset_count+1]
|
||||
next_supersetExercises = SupersetExercise.objects.filter(superset=next_superset).order_by('order').first()
|
||||
# Use prefetched data instead of re-querying
|
||||
next_superset_exercises = sorted(next_superset.supersetexercise_set.all(), key=lambda se: se.order)
|
||||
next_supersetExercises = next_superset_exercises[0] if next_superset_exercises else None
|
||||
|
||||
next_up_data = {
|
||||
"audio_url": next_supersetExercises.exercise.audio_url().lower(),
|
||||
|
||||
Reference in New Issue
Block a user